rfc7508.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #
  2. # This file is part of pyasn1-modules software.
  3. #
  4. # Created by Russ Housley with assistance from asn1ate v.0.6.0.
  5. #
  6. # Copyright (c) 2019, Vigil Security, LLC
  7. # License: http://snmplabs.com/pyasn1/license.html
  8. #
  9. # Securing Header Fields with S/MIME
  10. #
  11. # ASN.1 source from:
  12. # https://www.rfc-editor.org/rfc/rfc7508.txt
  13. # https://www.rfc-editor.org/errata/eid5875
  14. #
  15. from pyasn1.type import char
  16. from pyasn1.type import constraint
  17. from pyasn1.type import namedtype
  18. from pyasn1.type import namedval
  19. from pyasn1.type import univ
  20. from pyasn1_modules import rfc5652
  21. import string
  22. MAX = float('inf')
  23. class Algorithm(univ.Enumerated):
  24. namedValues = namedval.NamedValues(
  25. ('canonAlgorithmSimple', 0),
  26. ('canonAlgorithmRelaxed', 1)
  27. )
  28. class HeaderFieldStatus(univ.Integer):
  29. namedValues = namedval.NamedValues(
  30. ('duplicated', 0),
  31. ('deleted', 1),
  32. ('modified', 2)
  33. )
  34. class HeaderFieldName(char.VisibleString):
  35. subtypeSpec = (
  36. constraint.PermittedAlphabetConstraint(*string.printable) -
  37. constraint.PermittedAlphabetConstraint(':')
  38. )
  39. class HeaderFieldValue(char.UTF8String):
  40. pass
  41. class HeaderField(univ.Sequence):
  42. componentType = namedtype.NamedTypes(
  43. namedtype.NamedType('field-Name', HeaderFieldName()),
  44. namedtype.NamedType('field-Value', HeaderFieldValue()),
  45. namedtype.DefaultedNamedType('field-Status',
  46. HeaderFieldStatus().subtype(value='duplicated'))
  47. )
  48. class HeaderFields(univ.SequenceOf):
  49. componentType = HeaderField()
  50. subtypeSpec = constraint.ValueSizeConstraint(1, MAX)
  51. class SecureHeaderFields(univ.Set):
  52. componentType = namedtype.NamedTypes(
  53. namedtype.NamedType('canonAlgorithm', Algorithm()),
  54. namedtype.NamedType('secHeaderFields', HeaderFields())
  55. )
  56. id_aa = univ.ObjectIdentifier((1, 2, 840, 113549, 1, 9, 16, 2, ))
  57. id_aa_secureHeaderFieldsIdentifier = id_aa + (55, )
  58. # Map of Attribute Type OIDs to Attributes added to the
  59. # ones that are in rfc5652.py
  60. _cmsAttributesMapUpdate = {
  61. id_aa_secureHeaderFieldsIdentifier: SecureHeaderFields(),
  62. }
  63. rfc5652.cmsAttributesMap.update(_cmsAttributesMapUpdate)