You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.7 KiB

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