2 """DANE's SPKI hash calculator
5 from base64 import standard_b64decode
6 from hashlib import sha256
9 from pygost.asn1schemas.x509 import Certificate
12 lines = sys.stdin.read().split("-----")
13 idx = lines.index("BEGIN CERTIFICATE")
15 raise ValueError("PEM has no CERTIFICATE")
16 cert_raw = standard_b64decode(lines[idx + 1])
17 cert = Certificate().decod(cert_raw)
18 print(sha256(cert["tbsCertificate"]["subjectPublicKeyInfo"].encode()).hexdigest())