1# Copyright 2011 Sybren A. Stüvel <sybren@stuvel.eu> 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15"""ASN.1 definitions. 16 17Not all ASN.1-handling code use these definitions, but when it does, they should be here. 18""" 19 20from pyasn1.type import univ, namedtype, tag 21 22 23class PubKeyHeader(univ.Sequence): 24 componentType = namedtype.NamedTypes( 25 namedtype.NamedType('oid', univ.ObjectIdentifier()), 26 namedtype.NamedType('parameters', univ.Null()), 27 ) 28 29 30class OpenSSLPubKey(univ.Sequence): 31 componentType = namedtype.NamedTypes( 32 namedtype.NamedType('header', PubKeyHeader()), 33 34 # This little hack (the implicit tag) allows us to get a Bit String as Octet String 35 namedtype.NamedType('key', univ.OctetString().subtype( 36 implicitTag=tag.Tag(tagClass=0, tagFormat=0, tagId=3))), 37 ) 38 39 40class AsnPubKey(univ.Sequence): 41 """ASN.1 contents of DER encoded public key: 42 43 RSAPublicKey ::= SEQUENCE { 44 modulus INTEGER, -- n 45 publicExponent INTEGER, -- e 46 """ 47 48 componentType = namedtype.NamedTypes( 49 namedtype.NamedType('modulus', univ.Integer()), 50 namedtype.NamedType('publicExponent', univ.Integer()), 51 ) 52