1'''ASN.1 definitions.
2
3Not all ASN.1-handling code use these definitions, but when it does, they should be here.
4'''
5
6from pyasn1.type import univ, namedtype, tag
7
8class PubKeyHeader(univ.Sequence):
9    componentType = namedtype.NamedTypes(
10        namedtype.NamedType('oid', univ.ObjectIdentifier()),
11        namedtype.NamedType('parameters', univ.Null()),
12    )
13
14class OpenSSLPubKey(univ.Sequence):
15    componentType = namedtype.NamedTypes(
16        namedtype.NamedType('header', PubKeyHeader()),
17
18        # This little hack (the implicit tag) allows us to get a Bit String as Octet String
19        namedtype.NamedType('key', univ.OctetString().subtype(
20                                          implicitTag=tag.Tag(tagClass=0, tagFormat=0, tagId=3))),
21    )
22
23
24class AsnPubKey(univ.Sequence):
25    '''ASN.1 contents of DER encoded public key:
26
27    RSAPublicKey ::= SEQUENCE {
28         modulus           INTEGER,  -- n
29         publicExponent    INTEGER,  -- e
30    '''
31
32    componentType = namedtype.NamedTypes(
33        namedtype.NamedType('modulus', univ.Integer()),
34        namedtype.NamedType('publicExponent', univ.Integer()),
35    )
36