Source code of Windows XP (NT5)
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.

3806 lines
119 KiB

  1. /* Copyright (C) Microsoft Corporation, 1996 - 1999 All rights reserved. */
  2. /* ASN.1 definitions for GlobalDirectives */
  3. #pragma warning(push,3)
  4. #include <windows.h>
  5. #include "pkcs.h"
  6. #pragma warning (pop)
  7. // unreferenced inline function has been removed
  8. #pragma warning (disable: 4514)
  9. // unreferenced formal parameter
  10. #pragma warning (disable: 4100)
  11. // assignment within conditional expression
  12. #pragma warning (disable: 4706)
  13. ASN1module_t PKCS_Module = NULL;
  14. static int ASN1CALL ASN1Enc_ObjectID(ASN1encoding_t enc, ASN1uint32_t tag, ObjectID *val);
  15. static int ASN1CALL ASN1Enc_ObjectIdentifierType(ASN1encoding_t enc, ASN1uint32_t tag, ObjectIdentifierType *val);
  16. static int ASN1CALL ASN1Enc_OctetStringType(ASN1encoding_t enc, ASN1uint32_t tag, OctetStringType *val);
  17. static int ASN1CALL ASN1Enc_IntegerType(ASN1encoding_t enc, ASN1uint32_t tag, IntegerType *val);
  18. static int ASN1CALL ASN1Enc_HugeIntegerType(ASN1encoding_t enc, ASN1uint32_t tag, HugeIntegerType *val);
  19. static int ASN1CALL ASN1Enc_AlgorithmIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, AlgorithmIdentifier *val);
  20. static int ASN1CALL ASN1Enc_AlgorithmIdentifierNC2(ASN1encoding_t enc, ASN1uint32_t tag, AlgorithmIdentifierNC2 *val);
  21. static int ASN1CALL ASN1Enc_DigestAlgorithmIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, DigestAlgorithmIdentifier *val);
  22. static int ASN1CALL ASN1Enc_AlgorithmIdentifiers(ASN1encoding_t enc, ASN1uint32_t tag, AlgorithmIdentifiers *val);
  23. static int ASN1CALL ASN1Enc_AttributeSetValue(ASN1encoding_t enc, ASN1uint32_t tag, AttributeSetValue *val);
  24. static int ASN1CALL ASN1Enc_AttributeSetValueNC(ASN1encoding_t enc, ASN1uint32_t tag, AttributeSetValueNC *val);
  25. static int ASN1CALL ASN1Enc_SetOfAny(ASN1encoding_t enc, ASN1uint32_t tag, SetOfAny *val);
  26. static int ASN1CALL ASN1Enc_Attribute(ASN1encoding_t enc, ASN1uint32_t tag, Attribute *val);
  27. static int ASN1CALL ASN1Enc_AttributeNC2(ASN1encoding_t enc, ASN1uint32_t tag, AttributeNC2 *val);
  28. static int ASN1CALL ASN1Enc_Attributes(ASN1encoding_t enc, ASN1uint32_t tag, Attributes *val);
  29. static int ASN1CALL ASN1Enc_AttributesNC(ASN1encoding_t enc, ASN1uint32_t tag, AttributesNC *val);
  30. static int ASN1CALL ASN1Enc_AttributesNC2(ASN1encoding_t enc, ASN1uint32_t tag, AttributesNC2 *val);
  31. static int ASN1CALL ASN1Enc_Crls(ASN1encoding_t enc, ASN1uint32_t tag, Crls *val);
  32. static int ASN1CALL ASN1Enc_CrlsNC(ASN1encoding_t enc, ASN1uint32_t tag, CrlsNC *val);
  33. static int ASN1CALL ASN1Enc_ContentEncryptionAlgId(ASN1encoding_t enc, ASN1uint32_t tag, ContentEncryptionAlgId *val);
  34. static int ASN1CALL ASN1Enc_DigestEncryptionAlgId(ASN1encoding_t enc, ASN1uint32_t tag, DigestEncryptionAlgId *val);
  35. static int ASN1CALL ASN1Enc_DigestEncryptionAlgIdNC(ASN1encoding_t enc, ASN1uint32_t tag, DigestEncryptionAlgIdNC *val);
  36. static int ASN1CALL ASN1Enc_Certificates(ASN1encoding_t enc, ASN1uint32_t tag, Certificates *val);
  37. static int ASN1CALL ASN1Enc_CertificatesNC(ASN1encoding_t enc, ASN1uint32_t tag, CertificatesNC *val);
  38. static int ASN1CALL ASN1Enc_IssuerAndSerialNumber(ASN1encoding_t enc, ASN1uint32_t tag, IssuerAndSerialNumber *val);
  39. static int ASN1CALL ASN1Enc_KeyEncryptionAlgId(ASN1encoding_t enc, ASN1uint32_t tag, KeyEncryptionAlgId *val);
  40. static int ASN1CALL ASN1Enc_ContentInfo(ASN1encoding_t enc, ASN1uint32_t tag, ContentInfo *val);
  41. static int ASN1CALL ASN1Enc_ContentInfoNC(ASN1encoding_t enc, ASN1uint32_t tag, ContentInfoNC *val);
  42. static int ASN1CALL ASN1Enc_DigestAlgorithmIdentifiers(ASN1encoding_t enc, ASN1uint32_t tag, DigestAlgorithmIdentifiers *val);
  43. static int ASN1CALL ASN1Enc_DigestAlgorithmIdentifiersNC(ASN1encoding_t enc, ASN1uint32_t tag, DigestAlgorithmIdentifiersNC *val);
  44. static int ASN1CALL ASN1Enc_SignerInfos(ASN1encoding_t enc, ASN1uint32_t tag, SignerInfos *val);
  45. static int ASN1CALL ASN1Enc_DigestAlgorithmBlobs(ASN1encoding_t enc, ASN1uint32_t tag, DigestAlgorithmBlobs *val);
  46. static int ASN1CALL ASN1Enc_SignerInfosNC(ASN1encoding_t enc, ASN1uint32_t tag, SignerInfosNC *val);
  47. static int ASN1CALL ASN1Enc_SignerInfoWithAABlobs(ASN1encoding_t enc, ASN1uint32_t tag, SignerInfoWithAABlobs *val);
  48. static int ASN1CALL ASN1Enc_SignerInfoWithAABlob(ASN1encoding_t enc, ASN1uint32_t tag, SignerInfoWithAABlob *val);
  49. static int ASN1CALL ASN1Enc_SignerInfoWithAttrBlobs(ASN1encoding_t enc, ASN1uint32_t tag, SignerInfoWithAttrBlobs *val);
  50. static int ASN1CALL ASN1Enc_SignerInfoWithBlobs(ASN1encoding_t enc, ASN1uint32_t tag, SignerInfoWithBlobs *val);
  51. static int ASN1CALL ASN1Enc_RecipientInfos(ASN1encoding_t enc, ASN1uint32_t tag, RecipientInfos *val);
  52. static int ASN1CALL ASN1Enc_EncryptedContentInfo(ASN1encoding_t enc, ASN1uint32_t tag, EncryptedContentInfo *val);
  53. static int ASN1CALL ASN1Enc_RecipientInfo(ASN1encoding_t enc, ASN1uint32_t tag, RecipientInfo *val);
  54. static int ASN1CALL ASN1Enc_SignedAndEnvelopedData(ASN1encoding_t enc, ASN1uint32_t tag, SignedAndEnvelopedData *val);
  55. static int ASN1CALL ASN1Enc_DigestedData(ASN1encoding_t enc, ASN1uint32_t tag, DigestedData *val);
  56. static int ASN1CALL ASN1Enc_EncryptedData(ASN1encoding_t enc, ASN1uint32_t tag, EncryptedData *val);
  57. static int ASN1CALL ASN1Enc_CertIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, CertIdentifier *val);
  58. static int ASN1CALL ASN1Enc_OriginatorInfo(ASN1encoding_t enc, ASN1uint32_t tag, OriginatorInfo *val);
  59. static int ASN1CALL ASN1Enc_OriginatorInfoNC(ASN1encoding_t enc, ASN1uint32_t tag, OriginatorInfoNC *val);
  60. static int ASN1CALL ASN1Enc_CmsRecipientInfos(ASN1encoding_t enc, ASN1uint32_t tag, CmsRecipientInfos *val);
  61. static int ASN1CALL ASN1Enc_KeyTransRecipientInfo(ASN1encoding_t enc, ASN1uint32_t tag, KeyTransRecipientInfo *val);
  62. static int ASN1CALL ASN1Enc_OriginatorPublicKey(ASN1encoding_t enc, ASN1uint32_t tag, OriginatorPublicKey *val);
  63. static int ASN1CALL ASN1Enc_RecipientEncryptedKeys(ASN1encoding_t enc, ASN1uint32_t tag, RecipientEncryptedKeys *val);
  64. static int ASN1CALL ASN1Enc_OtherKeyAttribute(ASN1encoding_t enc, ASN1uint32_t tag, OtherKeyAttribute *val);
  65. static int ASN1CALL ASN1Enc_MailListKeyIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, MailListKeyIdentifier *val);
  66. static int ASN1CALL ASN1Enc_DigestInfo(ASN1encoding_t enc, ASN1uint32_t tag, DigestInfo *val);
  67. static int ASN1CALL ASN1Enc_SignedData(ASN1encoding_t enc, ASN1uint32_t tag, SignedData *val);
  68. static int ASN1CALL ASN1Enc_SignerInfo(ASN1encoding_t enc, ASN1uint32_t tag, SignerInfo *val);
  69. static int ASN1CALL ASN1Enc_SignedDataWithBlobs(ASN1encoding_t enc, ASN1uint32_t tag, SignedDataWithBlobs *val);
  70. static int ASN1CALL ASN1Enc_EnvelopedData(ASN1encoding_t enc, ASN1uint32_t tag, EnvelopedData *val);
  71. static int ASN1CALL ASN1Enc_CmsEnvelopedData(ASN1encoding_t enc, ASN1uint32_t tag, CmsEnvelopedData *val);
  72. static int ASN1CALL ASN1Enc_OriginatorIdentifierOrKey(ASN1encoding_t enc, ASN1uint32_t tag, OriginatorIdentifierOrKey *val);
  73. static int ASN1CALL ASN1Enc_RecipientKeyIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, RecipientKeyIdentifier *val);
  74. static int ASN1CALL ASN1Enc_MailListRecipientInfo(ASN1encoding_t enc, ASN1uint32_t tag, MailListRecipientInfo *val);
  75. static int ASN1CALL ASN1Enc_KeyAgreeRecipientInfo(ASN1encoding_t enc, ASN1uint32_t tag, KeyAgreeRecipientInfo *val);
  76. static int ASN1CALL ASN1Enc_RecipientIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, RecipientIdentifier *val);
  77. static int ASN1CALL ASN1Enc_CmsRecipientInfo(ASN1encoding_t enc, ASN1uint32_t tag, CmsRecipientInfo *val);
  78. static int ASN1CALL ASN1Enc_RecipientEncryptedKey(ASN1encoding_t enc, ASN1uint32_t tag, RecipientEncryptedKey *val);
  79. static int ASN1CALL ASN1Dec_ObjectID(ASN1decoding_t dec, ASN1uint32_t tag, ObjectID *val);
  80. static int ASN1CALL ASN1Dec_ObjectIdentifierType(ASN1decoding_t dec, ASN1uint32_t tag, ObjectIdentifierType *val);
  81. static int ASN1CALL ASN1Dec_OctetStringType(ASN1decoding_t dec, ASN1uint32_t tag, OctetStringType *val);
  82. static int ASN1CALL ASN1Dec_IntegerType(ASN1decoding_t dec, ASN1uint32_t tag, IntegerType *val);
  83. static int ASN1CALL ASN1Dec_HugeIntegerType(ASN1decoding_t dec, ASN1uint32_t tag, HugeIntegerType *val);
  84. static int ASN1CALL ASN1Dec_AlgorithmIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, AlgorithmIdentifier *val);
  85. static int ASN1CALL ASN1Dec_AlgorithmIdentifierNC2(ASN1decoding_t dec, ASN1uint32_t tag, AlgorithmIdentifierNC2 *val);
  86. static int ASN1CALL ASN1Dec_DigestAlgorithmIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, DigestAlgorithmIdentifier *val);
  87. static int ASN1CALL ASN1Dec_AlgorithmIdentifiers(ASN1decoding_t dec, ASN1uint32_t tag, AlgorithmIdentifiers *val);
  88. static int ASN1CALL ASN1Dec_AttributeSetValue(ASN1decoding_t dec, ASN1uint32_t tag, AttributeSetValue *val);
  89. static int ASN1CALL ASN1Dec_AttributeSetValueNC(ASN1decoding_t dec, ASN1uint32_t tag, AttributeSetValueNC *val);
  90. static int ASN1CALL ASN1Dec_SetOfAny(ASN1decoding_t dec, ASN1uint32_t tag, SetOfAny *val);
  91. static int ASN1CALL ASN1Dec_Attribute(ASN1decoding_t dec, ASN1uint32_t tag, Attribute *val);
  92. static int ASN1CALL ASN1Dec_AttributeNC2(ASN1decoding_t dec, ASN1uint32_t tag, AttributeNC2 *val);
  93. static int ASN1CALL ASN1Dec_Attributes(ASN1decoding_t dec, ASN1uint32_t tag, Attributes *val);
  94. static int ASN1CALL ASN1Dec_AttributesNC(ASN1decoding_t dec, ASN1uint32_t tag, AttributesNC *val);
  95. static int ASN1CALL ASN1Dec_AttributesNC2(ASN1decoding_t dec, ASN1uint32_t tag, AttributesNC2 *val);
  96. static int ASN1CALL ASN1Dec_Crls(ASN1decoding_t dec, ASN1uint32_t tag, Crls *val);
  97. static int ASN1CALL ASN1Dec_CrlsNC(ASN1decoding_t dec, ASN1uint32_t tag, CrlsNC *val);
  98. static int ASN1CALL ASN1Dec_ContentEncryptionAlgId(ASN1decoding_t dec, ASN1uint32_t tag, ContentEncryptionAlgId *val);
  99. static int ASN1CALL ASN1Dec_DigestEncryptionAlgId(ASN1decoding_t dec, ASN1uint32_t tag, DigestEncryptionAlgId *val);
  100. static int ASN1CALL ASN1Dec_DigestEncryptionAlgIdNC(ASN1decoding_t dec, ASN1uint32_t tag, DigestEncryptionAlgIdNC *val);
  101. static int ASN1CALL ASN1Dec_Certificates(ASN1decoding_t dec, ASN1uint32_t tag, Certificates *val);
  102. static int ASN1CALL ASN1Dec_CertificatesNC(ASN1decoding_t dec, ASN1uint32_t tag, CertificatesNC *val);
  103. static int ASN1CALL ASN1Dec_IssuerAndSerialNumber(ASN1decoding_t dec, ASN1uint32_t tag, IssuerAndSerialNumber *val);
  104. static int ASN1CALL ASN1Dec_KeyEncryptionAlgId(ASN1decoding_t dec, ASN1uint32_t tag, KeyEncryptionAlgId *val);
  105. static int ASN1CALL ASN1Dec_ContentInfo(ASN1decoding_t dec, ASN1uint32_t tag, ContentInfo *val);
  106. static int ASN1CALL ASN1Dec_ContentInfoNC(ASN1decoding_t dec, ASN1uint32_t tag, ContentInfoNC *val);
  107. static int ASN1CALL ASN1Dec_DigestAlgorithmIdentifiers(ASN1decoding_t dec, ASN1uint32_t tag, DigestAlgorithmIdentifiers *val);
  108. static int ASN1CALL ASN1Dec_DigestAlgorithmIdentifiersNC(ASN1decoding_t dec, ASN1uint32_t tag, DigestAlgorithmIdentifiersNC *val);
  109. static int ASN1CALL ASN1Dec_SignerInfos(ASN1decoding_t dec, ASN1uint32_t tag, SignerInfos *val);
  110. static int ASN1CALL ASN1Dec_DigestAlgorithmBlobs(ASN1decoding_t dec, ASN1uint32_t tag, DigestAlgorithmBlobs *val);
  111. static int ASN1CALL ASN1Dec_SignerInfosNC(ASN1decoding_t dec, ASN1uint32_t tag, SignerInfosNC *val);
  112. static int ASN1CALL ASN1Dec_SignerInfoWithAABlobs(ASN1decoding_t dec, ASN1uint32_t tag, SignerInfoWithAABlobs *val);
  113. static int ASN1CALL ASN1Dec_SignerInfoWithAABlob(ASN1decoding_t dec, ASN1uint32_t tag, SignerInfoWithAABlob *val);
  114. static int ASN1CALL ASN1Dec_SignerInfoWithAttrBlobs(ASN1decoding_t dec, ASN1uint32_t tag, SignerInfoWithAttrBlobs *val);
  115. static int ASN1CALL ASN1Dec_SignerInfoWithBlobs(ASN1decoding_t dec, ASN1uint32_t tag, SignerInfoWithBlobs *val);
  116. static int ASN1CALL ASN1Dec_RecipientInfos(ASN1decoding_t dec, ASN1uint32_t tag, RecipientInfos *val);
  117. static int ASN1CALL ASN1Dec_EncryptedContentInfo(ASN1decoding_t dec, ASN1uint32_t tag, EncryptedContentInfo *val);
  118. static int ASN1CALL ASN1Dec_RecipientInfo(ASN1decoding_t dec, ASN1uint32_t tag, RecipientInfo *val);
  119. static int ASN1CALL ASN1Dec_SignedAndEnvelopedData(ASN1decoding_t dec, ASN1uint32_t tag, SignedAndEnvelopedData *val);
  120. static int ASN1CALL ASN1Dec_DigestedData(ASN1decoding_t dec, ASN1uint32_t tag, DigestedData *val);
  121. static int ASN1CALL ASN1Dec_EncryptedData(ASN1decoding_t dec, ASN1uint32_t tag, EncryptedData *val);
  122. static int ASN1CALL ASN1Dec_CertIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, CertIdentifier *val);
  123. static int ASN1CALL ASN1Dec_OriginatorInfo(ASN1decoding_t dec, ASN1uint32_t tag, OriginatorInfo *val);
  124. static int ASN1CALL ASN1Dec_OriginatorInfoNC(ASN1decoding_t dec, ASN1uint32_t tag, OriginatorInfoNC *val);
  125. static int ASN1CALL ASN1Dec_CmsRecipientInfos(ASN1decoding_t dec, ASN1uint32_t tag, CmsRecipientInfos *val);
  126. static int ASN1CALL ASN1Dec_KeyTransRecipientInfo(ASN1decoding_t dec, ASN1uint32_t tag, KeyTransRecipientInfo *val);
  127. static int ASN1CALL ASN1Dec_OriginatorPublicKey(ASN1decoding_t dec, ASN1uint32_t tag, OriginatorPublicKey *val);
  128. static int ASN1CALL ASN1Dec_RecipientEncryptedKeys(ASN1decoding_t dec, ASN1uint32_t tag, RecipientEncryptedKeys *val);
  129. static int ASN1CALL ASN1Dec_OtherKeyAttribute(ASN1decoding_t dec, ASN1uint32_t tag, OtherKeyAttribute *val);
  130. static int ASN1CALL ASN1Dec_MailListKeyIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, MailListKeyIdentifier *val);
  131. static int ASN1CALL ASN1Dec_DigestInfo(ASN1decoding_t dec, ASN1uint32_t tag, DigestInfo *val);
  132. static int ASN1CALL ASN1Dec_SignedData(ASN1decoding_t dec, ASN1uint32_t tag, SignedData *val);
  133. static int ASN1CALL ASN1Dec_SignerInfo(ASN1decoding_t dec, ASN1uint32_t tag, SignerInfo *val);
  134. static int ASN1CALL ASN1Dec_SignedDataWithBlobs(ASN1decoding_t dec, ASN1uint32_t tag, SignedDataWithBlobs *val);
  135. static int ASN1CALL ASN1Dec_EnvelopedData(ASN1decoding_t dec, ASN1uint32_t tag, EnvelopedData *val);
  136. static int ASN1CALL ASN1Dec_CmsEnvelopedData(ASN1decoding_t dec, ASN1uint32_t tag, CmsEnvelopedData *val);
  137. static int ASN1CALL ASN1Dec_OriginatorIdentifierOrKey(ASN1decoding_t dec, ASN1uint32_t tag, OriginatorIdentifierOrKey *val);
  138. static int ASN1CALL ASN1Dec_RecipientKeyIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, RecipientKeyIdentifier *val);
  139. static int ASN1CALL ASN1Dec_MailListRecipientInfo(ASN1decoding_t dec, ASN1uint32_t tag, MailListRecipientInfo *val);
  140. static int ASN1CALL ASN1Dec_KeyAgreeRecipientInfo(ASN1decoding_t dec, ASN1uint32_t tag, KeyAgreeRecipientInfo *val);
  141. static int ASN1CALL ASN1Dec_RecipientIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, RecipientIdentifier *val);
  142. static int ASN1CALL ASN1Dec_CmsRecipientInfo(ASN1decoding_t dec, ASN1uint32_t tag, CmsRecipientInfo *val);
  143. static int ASN1CALL ASN1Dec_RecipientEncryptedKey(ASN1decoding_t dec, ASN1uint32_t tag, RecipientEncryptedKey *val);
  144. static void ASN1CALL ASN1Free_ObjectID(ObjectID *val);
  145. static void ASN1CALL ASN1Free_ObjectIdentifierType(ObjectIdentifierType *val);
  146. static void ASN1CALL ASN1Free_OctetStringType(OctetStringType *val);
  147. static void ASN1CALL ASN1Free_HugeIntegerType(HugeIntegerType *val);
  148. static void ASN1CALL ASN1Free_AlgorithmIdentifier(AlgorithmIdentifier *val);
  149. static void ASN1CALL ASN1Free_AlgorithmIdentifierNC2(AlgorithmIdentifierNC2 *val);
  150. static void ASN1CALL ASN1Free_DigestAlgorithmIdentifier(DigestAlgorithmIdentifier *val);
  151. static void ASN1CALL ASN1Free_AlgorithmIdentifiers(AlgorithmIdentifiers *val);
  152. static void ASN1CALL ASN1Free_AttributeSetValue(AttributeSetValue *val);
  153. static void ASN1CALL ASN1Free_AttributeSetValueNC(AttributeSetValueNC *val);
  154. static void ASN1CALL ASN1Free_SetOfAny(SetOfAny *val);
  155. static void ASN1CALL ASN1Free_Attribute(Attribute *val);
  156. static void ASN1CALL ASN1Free_AttributeNC2(AttributeNC2 *val);
  157. static void ASN1CALL ASN1Free_Attributes(Attributes *val);
  158. static void ASN1CALL ASN1Free_AttributesNC(AttributesNC *val);
  159. static void ASN1CALL ASN1Free_AttributesNC2(AttributesNC2 *val);
  160. static void ASN1CALL ASN1Free_Crls(Crls *val);
  161. static void ASN1CALL ASN1Free_CrlsNC(CrlsNC *val);
  162. static void ASN1CALL ASN1Free_ContentEncryptionAlgId(ContentEncryptionAlgId *val);
  163. static void ASN1CALL ASN1Free_DigestEncryptionAlgId(DigestEncryptionAlgId *val);
  164. static void ASN1CALL ASN1Free_DigestEncryptionAlgIdNC(DigestEncryptionAlgIdNC *val);
  165. static void ASN1CALL ASN1Free_Certificates(Certificates *val);
  166. static void ASN1CALL ASN1Free_CertificatesNC(CertificatesNC *val);
  167. static void ASN1CALL ASN1Free_IssuerAndSerialNumber(IssuerAndSerialNumber *val);
  168. static void ASN1CALL ASN1Free_KeyEncryptionAlgId(KeyEncryptionAlgId *val);
  169. static void ASN1CALL ASN1Free_ContentInfo(ContentInfo *val);
  170. static void ASN1CALL ASN1Free_ContentInfoNC(ContentInfoNC *val);
  171. static void ASN1CALL ASN1Free_DigestAlgorithmIdentifiers(DigestAlgorithmIdentifiers *val);
  172. static void ASN1CALL ASN1Free_DigestAlgorithmIdentifiersNC(DigestAlgorithmIdentifiersNC *val);
  173. static void ASN1CALL ASN1Free_SignerInfos(SignerInfos *val);
  174. static void ASN1CALL ASN1Free_DigestAlgorithmBlobs(DigestAlgorithmBlobs *val);
  175. static void ASN1CALL ASN1Free_SignerInfosNC(SignerInfosNC *val);
  176. static void ASN1CALL ASN1Free_SignerInfoWithAABlobs(SignerInfoWithAABlobs *val);
  177. static void ASN1CALL ASN1Free_SignerInfoWithAABlob(SignerInfoWithAABlob *val);
  178. static void ASN1CALL ASN1Free_SignerInfoWithAttrBlobs(SignerInfoWithAttrBlobs *val);
  179. static void ASN1CALL ASN1Free_SignerInfoWithBlobs(SignerInfoWithBlobs *val);
  180. static void ASN1CALL ASN1Free_RecipientInfos(RecipientInfos *val);
  181. static void ASN1CALL ASN1Free_EncryptedContentInfo(EncryptedContentInfo *val);
  182. static void ASN1CALL ASN1Free_RecipientInfo(RecipientInfo *val);
  183. static void ASN1CALL ASN1Free_SignedAndEnvelopedData(SignedAndEnvelopedData *val);
  184. static void ASN1CALL ASN1Free_DigestedData(DigestedData *val);
  185. static void ASN1CALL ASN1Free_EncryptedData(EncryptedData *val);
  186. static void ASN1CALL ASN1Free_CertIdentifier(CertIdentifier *val);
  187. static void ASN1CALL ASN1Free_OriginatorInfo(OriginatorInfo *val);
  188. static void ASN1CALL ASN1Free_OriginatorInfoNC(OriginatorInfoNC *val);
  189. static void ASN1CALL ASN1Free_CmsRecipientInfos(CmsRecipientInfos *val);
  190. static void ASN1CALL ASN1Free_KeyTransRecipientInfo(KeyTransRecipientInfo *val);
  191. static void ASN1CALL ASN1Free_OriginatorPublicKey(OriginatorPublicKey *val);
  192. static void ASN1CALL ASN1Free_RecipientEncryptedKeys(RecipientEncryptedKeys *val);
  193. static void ASN1CALL ASN1Free_OtherKeyAttribute(OtherKeyAttribute *val);
  194. static void ASN1CALL ASN1Free_MailListKeyIdentifier(MailListKeyIdentifier *val);
  195. static void ASN1CALL ASN1Free_DigestInfo(DigestInfo *val);
  196. static void ASN1CALL ASN1Free_SignedData(SignedData *val);
  197. static void ASN1CALL ASN1Free_SignerInfo(SignerInfo *val);
  198. static void ASN1CALL ASN1Free_SignedDataWithBlobs(SignedDataWithBlobs *val);
  199. static void ASN1CALL ASN1Free_EnvelopedData(EnvelopedData *val);
  200. static void ASN1CALL ASN1Free_CmsEnvelopedData(CmsEnvelopedData *val);
  201. static void ASN1CALL ASN1Free_OriginatorIdentifierOrKey(OriginatorIdentifierOrKey *val);
  202. static void ASN1CALL ASN1Free_RecipientKeyIdentifier(RecipientKeyIdentifier *val);
  203. static void ASN1CALL ASN1Free_MailListRecipientInfo(MailListRecipientInfo *val);
  204. static void ASN1CALL ASN1Free_KeyAgreeRecipientInfo(KeyAgreeRecipientInfo *val);
  205. static void ASN1CALL ASN1Free_RecipientIdentifier(RecipientIdentifier *val);
  206. static void ASN1CALL ASN1Free_CmsRecipientInfo(CmsRecipientInfo *val);
  207. static void ASN1CALL ASN1Free_RecipientEncryptedKey(RecipientEncryptedKey *val);
  208. typedef ASN1BerEncFun_t ASN1EncFun_t;
  209. static const ASN1EncFun_t encfntab[48] = {
  210. (ASN1EncFun_t) ASN1Enc_ObjectID,
  211. (ASN1EncFun_t) ASN1Enc_ObjectIdentifierType,
  212. (ASN1EncFun_t) ASN1Enc_OctetStringType,
  213. (ASN1EncFun_t) ASN1Enc_IntegerType,
  214. (ASN1EncFun_t) ASN1Enc_HugeIntegerType,
  215. (ASN1EncFun_t) ASN1Enc_AlgorithmIdentifier,
  216. (ASN1EncFun_t) ASN1Enc_AlgorithmIdentifierNC2,
  217. (ASN1EncFun_t) ASN1Enc_AlgorithmIdentifiers,
  218. (ASN1EncFun_t) ASN1Enc_AttributeSetValue,
  219. (ASN1EncFun_t) ASN1Enc_AttributeSetValueNC,
  220. (ASN1EncFun_t) ASN1Enc_SetOfAny,
  221. (ASN1EncFun_t) ASN1Enc_AttributeNC2,
  222. (ASN1EncFun_t) ASN1Enc_Attributes,
  223. (ASN1EncFun_t) ASN1Enc_AttributesNC,
  224. (ASN1EncFun_t) ASN1Enc_AttributesNC2,
  225. (ASN1EncFun_t) ASN1Enc_CrlsNC,
  226. (ASN1EncFun_t) ASN1Enc_CertificatesNC,
  227. (ASN1EncFun_t) ASN1Enc_IssuerAndSerialNumber,
  228. (ASN1EncFun_t) ASN1Enc_ContentInfo,
  229. (ASN1EncFun_t) ASN1Enc_ContentInfoNC,
  230. (ASN1EncFun_t) ASN1Enc_DigestAlgorithmIdentifiersNC,
  231. (ASN1EncFun_t) ASN1Enc_SignerInfos,
  232. (ASN1EncFun_t) ASN1Enc_DigestAlgorithmBlobs,
  233. (ASN1EncFun_t) ASN1Enc_SignerInfosNC,
  234. (ASN1EncFun_t) ASN1Enc_SignerInfoWithAABlobs,
  235. (ASN1EncFun_t) ASN1Enc_SignerInfoWithAABlob,
  236. (ASN1EncFun_t) ASN1Enc_SignerInfoWithAttrBlobs,
  237. (ASN1EncFun_t) ASN1Enc_SignerInfoWithBlobs,
  238. (ASN1EncFun_t) ASN1Enc_RecipientInfos,
  239. (ASN1EncFun_t) ASN1Enc_EncryptedContentInfo,
  240. (ASN1EncFun_t) ASN1Enc_RecipientInfo,
  241. (ASN1EncFun_t) ASN1Enc_SignedAndEnvelopedData,
  242. (ASN1EncFun_t) ASN1Enc_DigestedData,
  243. (ASN1EncFun_t) ASN1Enc_EncryptedData,
  244. (ASN1EncFun_t) ASN1Enc_CertIdentifier,
  245. (ASN1EncFun_t) ASN1Enc_OriginatorInfo,
  246. (ASN1EncFun_t) ASN1Enc_OriginatorInfoNC,
  247. (ASN1EncFun_t) ASN1Enc_CmsRecipientInfos,
  248. (ASN1EncFun_t) ASN1Enc_KeyTransRecipientInfo,
  249. (ASN1EncFun_t) ASN1Enc_DigestInfo,
  250. (ASN1EncFun_t) ASN1Enc_SignedData,
  251. (ASN1EncFun_t) ASN1Enc_SignerInfo,
  252. (ASN1EncFun_t) ASN1Enc_SignedDataWithBlobs,
  253. (ASN1EncFun_t) ASN1Enc_EnvelopedData,
  254. (ASN1EncFun_t) ASN1Enc_CmsEnvelopedData,
  255. (ASN1EncFun_t) ASN1Enc_MailListRecipientInfo,
  256. (ASN1EncFun_t) ASN1Enc_KeyAgreeRecipientInfo,
  257. (ASN1EncFun_t) ASN1Enc_CmsRecipientInfo,
  258. };
  259. typedef ASN1BerDecFun_t ASN1DecFun_t;
  260. static const ASN1DecFun_t decfntab[48] = {
  261. (ASN1DecFun_t) ASN1Dec_ObjectID,
  262. (ASN1DecFun_t) ASN1Dec_ObjectIdentifierType,
  263. (ASN1DecFun_t) ASN1Dec_OctetStringType,
  264. (ASN1DecFun_t) ASN1Dec_IntegerType,
  265. (ASN1DecFun_t) ASN1Dec_HugeIntegerType,
  266. (ASN1DecFun_t) ASN1Dec_AlgorithmIdentifier,
  267. (ASN1DecFun_t) ASN1Dec_AlgorithmIdentifierNC2,
  268. (ASN1DecFun_t) ASN1Dec_AlgorithmIdentifiers,
  269. (ASN1DecFun_t) ASN1Dec_AttributeSetValue,
  270. (ASN1DecFun_t) ASN1Dec_AttributeSetValueNC,
  271. (ASN1DecFun_t) ASN1Dec_SetOfAny,
  272. (ASN1DecFun_t) ASN1Dec_AttributeNC2,
  273. (ASN1DecFun_t) ASN1Dec_Attributes,
  274. (ASN1DecFun_t) ASN1Dec_AttributesNC,
  275. (ASN1DecFun_t) ASN1Dec_AttributesNC2,
  276. (ASN1DecFun_t) ASN1Dec_CrlsNC,
  277. (ASN1DecFun_t) ASN1Dec_CertificatesNC,
  278. (ASN1DecFun_t) ASN1Dec_IssuerAndSerialNumber,
  279. (ASN1DecFun_t) ASN1Dec_ContentInfo,
  280. (ASN1DecFun_t) ASN1Dec_ContentInfoNC,
  281. (ASN1DecFun_t) ASN1Dec_DigestAlgorithmIdentifiersNC,
  282. (ASN1DecFun_t) ASN1Dec_SignerInfos,
  283. (ASN1DecFun_t) ASN1Dec_DigestAlgorithmBlobs,
  284. (ASN1DecFun_t) ASN1Dec_SignerInfosNC,
  285. (ASN1DecFun_t) ASN1Dec_SignerInfoWithAABlobs,
  286. (ASN1DecFun_t) ASN1Dec_SignerInfoWithAABlob,
  287. (ASN1DecFun_t) ASN1Dec_SignerInfoWithAttrBlobs,
  288. (ASN1DecFun_t) ASN1Dec_SignerInfoWithBlobs,
  289. (ASN1DecFun_t) ASN1Dec_RecipientInfos,
  290. (ASN1DecFun_t) ASN1Dec_EncryptedContentInfo,
  291. (ASN1DecFun_t) ASN1Dec_RecipientInfo,
  292. (ASN1DecFun_t) ASN1Dec_SignedAndEnvelopedData,
  293. (ASN1DecFun_t) ASN1Dec_DigestedData,
  294. (ASN1DecFun_t) ASN1Dec_EncryptedData,
  295. (ASN1DecFun_t) ASN1Dec_CertIdentifier,
  296. (ASN1DecFun_t) ASN1Dec_OriginatorInfo,
  297. (ASN1DecFun_t) ASN1Dec_OriginatorInfoNC,
  298. (ASN1DecFun_t) ASN1Dec_CmsRecipientInfos,
  299. (ASN1DecFun_t) ASN1Dec_KeyTransRecipientInfo,
  300. (ASN1DecFun_t) ASN1Dec_DigestInfo,
  301. (ASN1DecFun_t) ASN1Dec_SignedData,
  302. (ASN1DecFun_t) ASN1Dec_SignerInfo,
  303. (ASN1DecFun_t) ASN1Dec_SignedDataWithBlobs,
  304. (ASN1DecFun_t) ASN1Dec_EnvelopedData,
  305. (ASN1DecFun_t) ASN1Dec_CmsEnvelopedData,
  306. (ASN1DecFun_t) ASN1Dec_MailListRecipientInfo,
  307. (ASN1DecFun_t) ASN1Dec_KeyAgreeRecipientInfo,
  308. (ASN1DecFun_t) ASN1Dec_CmsRecipientInfo,
  309. };
  310. static const ASN1FreeFun_t freefntab[48] = {
  311. (ASN1FreeFun_t) ASN1Free_ObjectID,
  312. (ASN1FreeFun_t) ASN1Free_ObjectIdentifierType,
  313. (ASN1FreeFun_t) ASN1Free_OctetStringType,
  314. (ASN1FreeFun_t) NULL,
  315. (ASN1FreeFun_t) ASN1Free_HugeIntegerType,
  316. (ASN1FreeFun_t) ASN1Free_AlgorithmIdentifier,
  317. (ASN1FreeFun_t) ASN1Free_AlgorithmIdentifierNC2,
  318. (ASN1FreeFun_t) ASN1Free_AlgorithmIdentifiers,
  319. (ASN1FreeFun_t) ASN1Free_AttributeSetValue,
  320. (ASN1FreeFun_t) ASN1Free_AttributeSetValueNC,
  321. (ASN1FreeFun_t) ASN1Free_SetOfAny,
  322. (ASN1FreeFun_t) ASN1Free_AttributeNC2,
  323. (ASN1FreeFun_t) ASN1Free_Attributes,
  324. (ASN1FreeFun_t) ASN1Free_AttributesNC,
  325. (ASN1FreeFun_t) ASN1Free_AttributesNC2,
  326. (ASN1FreeFun_t) ASN1Free_CrlsNC,
  327. (ASN1FreeFun_t) ASN1Free_CertificatesNC,
  328. (ASN1FreeFun_t) ASN1Free_IssuerAndSerialNumber,
  329. (ASN1FreeFun_t) ASN1Free_ContentInfo,
  330. (ASN1FreeFun_t) ASN1Free_ContentInfoNC,
  331. (ASN1FreeFun_t) ASN1Free_DigestAlgorithmIdentifiersNC,
  332. (ASN1FreeFun_t) ASN1Free_SignerInfos,
  333. (ASN1FreeFun_t) ASN1Free_DigestAlgorithmBlobs,
  334. (ASN1FreeFun_t) ASN1Free_SignerInfosNC,
  335. (ASN1FreeFun_t) ASN1Free_SignerInfoWithAABlobs,
  336. (ASN1FreeFun_t) ASN1Free_SignerInfoWithAABlob,
  337. (ASN1FreeFun_t) ASN1Free_SignerInfoWithAttrBlobs,
  338. (ASN1FreeFun_t) ASN1Free_SignerInfoWithBlobs,
  339. (ASN1FreeFun_t) ASN1Free_RecipientInfos,
  340. (ASN1FreeFun_t) ASN1Free_EncryptedContentInfo,
  341. (ASN1FreeFun_t) ASN1Free_RecipientInfo,
  342. (ASN1FreeFun_t) ASN1Free_SignedAndEnvelopedData,
  343. (ASN1FreeFun_t) ASN1Free_DigestedData,
  344. (ASN1FreeFun_t) ASN1Free_EncryptedData,
  345. (ASN1FreeFun_t) ASN1Free_CertIdentifier,
  346. (ASN1FreeFun_t) ASN1Free_OriginatorInfo,
  347. (ASN1FreeFun_t) ASN1Free_OriginatorInfoNC,
  348. (ASN1FreeFun_t) ASN1Free_CmsRecipientInfos,
  349. (ASN1FreeFun_t) ASN1Free_KeyTransRecipientInfo,
  350. (ASN1FreeFun_t) ASN1Free_DigestInfo,
  351. (ASN1FreeFun_t) ASN1Free_SignedData,
  352. (ASN1FreeFun_t) ASN1Free_SignerInfo,
  353. (ASN1FreeFun_t) ASN1Free_SignedDataWithBlobs,
  354. (ASN1FreeFun_t) ASN1Free_EnvelopedData,
  355. (ASN1FreeFun_t) ASN1Free_CmsEnvelopedData,
  356. (ASN1FreeFun_t) ASN1Free_MailListRecipientInfo,
  357. (ASN1FreeFun_t) ASN1Free_KeyAgreeRecipientInfo,
  358. (ASN1FreeFun_t) ASN1Free_CmsRecipientInfo,
  359. };
  360. static const ULONG sizetab[48] = {
  361. SIZE_PKCS_Module_PDU_0,
  362. SIZE_PKCS_Module_PDU_1,
  363. SIZE_PKCS_Module_PDU_2,
  364. SIZE_PKCS_Module_PDU_3,
  365. SIZE_PKCS_Module_PDU_4,
  366. SIZE_PKCS_Module_PDU_5,
  367. SIZE_PKCS_Module_PDU_6,
  368. SIZE_PKCS_Module_PDU_7,
  369. SIZE_PKCS_Module_PDU_8,
  370. SIZE_PKCS_Module_PDU_9,
  371. SIZE_PKCS_Module_PDU_10,
  372. SIZE_PKCS_Module_PDU_11,
  373. SIZE_PKCS_Module_PDU_12,
  374. SIZE_PKCS_Module_PDU_13,
  375. SIZE_PKCS_Module_PDU_14,
  376. SIZE_PKCS_Module_PDU_15,
  377. SIZE_PKCS_Module_PDU_16,
  378. SIZE_PKCS_Module_PDU_17,
  379. SIZE_PKCS_Module_PDU_18,
  380. SIZE_PKCS_Module_PDU_19,
  381. SIZE_PKCS_Module_PDU_20,
  382. SIZE_PKCS_Module_PDU_21,
  383. SIZE_PKCS_Module_PDU_22,
  384. SIZE_PKCS_Module_PDU_23,
  385. SIZE_PKCS_Module_PDU_24,
  386. SIZE_PKCS_Module_PDU_25,
  387. SIZE_PKCS_Module_PDU_26,
  388. SIZE_PKCS_Module_PDU_27,
  389. SIZE_PKCS_Module_PDU_28,
  390. SIZE_PKCS_Module_PDU_29,
  391. SIZE_PKCS_Module_PDU_30,
  392. SIZE_PKCS_Module_PDU_31,
  393. SIZE_PKCS_Module_PDU_32,
  394. SIZE_PKCS_Module_PDU_33,
  395. SIZE_PKCS_Module_PDU_34,
  396. SIZE_PKCS_Module_PDU_35,
  397. SIZE_PKCS_Module_PDU_36,
  398. SIZE_PKCS_Module_PDU_37,
  399. SIZE_PKCS_Module_PDU_38,
  400. SIZE_PKCS_Module_PDU_39,
  401. SIZE_PKCS_Module_PDU_40,
  402. SIZE_PKCS_Module_PDU_41,
  403. SIZE_PKCS_Module_PDU_42,
  404. SIZE_PKCS_Module_PDU_43,
  405. SIZE_PKCS_Module_PDU_44,
  406. SIZE_PKCS_Module_PDU_45,
  407. SIZE_PKCS_Module_PDU_46,
  408. SIZE_PKCS_Module_PDU_47,
  409. };
  410. /* forward declarations of values: */
  411. /* definitions of value components: */
  412. /* definitions of values: */
  413. void ASN1CALL PKCS_Module_Startup(void)
  414. {
  415. PKCS_Module = ASN1_CreateModule(0x10000, ASN1_BER_RULE_DER, ASN1FLAGS_NOASSERT, 48, (const ASN1GenericFun_t *) encfntab, (const ASN1GenericFun_t *) decfntab, freefntab, sizetab, 0x73636b70);
  416. }
  417. void ASN1CALL PKCS_Module_Cleanup(void)
  418. {
  419. ASN1_CloseModule(PKCS_Module);
  420. PKCS_Module = NULL;
  421. }
  422. static int ASN1CALL ASN1Enc_ObjectID(ASN1encoding_t enc, ASN1uint32_t tag, ObjectID *val)
  423. {
  424. if (!ASN1BEREncObjectIdentifier2(enc, tag ? tag : 0x6, val))
  425. return 0;
  426. return 1;
  427. }
  428. static int ASN1CALL ASN1Dec_ObjectID(ASN1decoding_t dec, ASN1uint32_t tag, ObjectID *val)
  429. {
  430. if (!ASN1BERDecObjectIdentifier2(dec, tag ? tag : 0x6, val))
  431. return 0;
  432. return 1;
  433. }
  434. static void ASN1CALL ASN1Free_ObjectID(ObjectID *val)
  435. {
  436. if (val) {
  437. }
  438. }
  439. static int ASN1CALL ASN1Enc_ObjectIdentifierType(ASN1encoding_t enc, ASN1uint32_t tag, ObjectIdentifierType *val)
  440. {
  441. if (!ASN1BEREncObjectIdentifier2(enc, tag ? tag : 0x6, val))
  442. return 0;
  443. return 1;
  444. }
  445. static int ASN1CALL ASN1Dec_ObjectIdentifierType(ASN1decoding_t dec, ASN1uint32_t tag, ObjectIdentifierType *val)
  446. {
  447. if (!ASN1BERDecObjectIdentifier2(dec, tag ? tag : 0x6, val))
  448. return 0;
  449. return 1;
  450. }
  451. static void ASN1CALL ASN1Free_ObjectIdentifierType(ObjectIdentifierType *val)
  452. {
  453. if (val) {
  454. }
  455. }
  456. static int ASN1CALL ASN1Enc_OctetStringType(ASN1encoding_t enc, ASN1uint32_t tag, OctetStringType *val)
  457. {
  458. if (!ASN1DEREncOctetString(enc, tag ? tag : 0x4, (val)->length, (val)->value))
  459. return 0;
  460. return 1;
  461. }
  462. static int ASN1CALL ASN1Dec_OctetStringType(ASN1decoding_t dec, ASN1uint32_t tag, OctetStringType *val)
  463. {
  464. if (!ASN1BERDecOctetString(dec, tag ? tag : 0x4, val))
  465. return 0;
  466. return 1;
  467. }
  468. static void ASN1CALL ASN1Free_OctetStringType(OctetStringType *val)
  469. {
  470. if (val) {
  471. ASN1octetstring_free(val);
  472. }
  473. }
  474. static int ASN1CALL ASN1Enc_IntegerType(ASN1encoding_t enc, ASN1uint32_t tag, IntegerType *val)
  475. {
  476. if (!ASN1BEREncS32(enc, tag ? tag : 0x2, *val))
  477. return 0;
  478. return 1;
  479. }
  480. static int ASN1CALL ASN1Dec_IntegerType(ASN1decoding_t dec, ASN1uint32_t tag, IntegerType *val)
  481. {
  482. if (!ASN1BERDecS32Val(dec, tag ? tag : 0x2, val))
  483. return 0;
  484. return 1;
  485. }
  486. static int ASN1CALL ASN1Enc_HugeIntegerType(ASN1encoding_t enc, ASN1uint32_t tag, HugeIntegerType *val)
  487. {
  488. if (!ASN1BEREncSX(enc, tag ? tag : 0x2, val))
  489. return 0;
  490. return 1;
  491. }
  492. static int ASN1CALL ASN1Dec_HugeIntegerType(ASN1decoding_t dec, ASN1uint32_t tag, HugeIntegerType *val)
  493. {
  494. if (!ASN1BERDecSXVal(dec, tag ? tag : 0x2, val))
  495. return 0;
  496. return 1;
  497. }
  498. static void ASN1CALL ASN1Free_HugeIntegerType(HugeIntegerType *val)
  499. {
  500. if (val) {
  501. ASN1intx_free(val);
  502. }
  503. }
  504. static int ASN1CALL ASN1Enc_AlgorithmIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, AlgorithmIdentifier *val)
  505. {
  506. ASN1uint32_t nLenOff;
  507. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  508. return 0;
  509. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->algorithm))
  510. return 0;
  511. if ((val)->o[0] & 0x80) {
  512. if (!ASN1BEREncOpenType(enc, &(val)->parameters))
  513. return 0;
  514. }
  515. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  516. return 0;
  517. return 1;
  518. }
  519. static int ASN1CALL ASN1Dec_AlgorithmIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, AlgorithmIdentifier *val)
  520. {
  521. ASN1decoding_t dd;
  522. ASN1octet_t *di;
  523. ASN1uint32_t t;
  524. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  525. return 0;
  526. ZeroMemory((val)->o, 1);
  527. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->algorithm))
  528. return 0;
  529. if (ASN1BERDecPeekTag(dd, &t)) {
  530. (val)->o[0] |= 0x80;
  531. if (!ASN1BERDecOpenType(dd, &(val)->parameters))
  532. return 0;
  533. }
  534. if (!ASN1BERDecEndOfContents(dec, dd, di))
  535. return 0;
  536. return 1;
  537. }
  538. static void ASN1CALL ASN1Free_AlgorithmIdentifier(AlgorithmIdentifier *val)
  539. {
  540. if (val) {
  541. if ((val)->o[0] & 0x80) {
  542. ASN1open_free(&(val)->parameters);
  543. }
  544. }
  545. }
  546. static int ASN1CALL ASN1Enc_AlgorithmIdentifierNC2(ASN1encoding_t enc, ASN1uint32_t tag, AlgorithmIdentifierNC2 *val)
  547. {
  548. ASN1uint32_t nLenOff;
  549. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  550. return 0;
  551. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->algorithm))
  552. return 0;
  553. if ((val)->o[0] & 0x80) {
  554. if (!ASN1BEREncOpenType(enc, &(val)->parameters))
  555. return 0;
  556. }
  557. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  558. return 0;
  559. return 1;
  560. }
  561. static int ASN1CALL ASN1Dec_AlgorithmIdentifierNC2(ASN1decoding_t dec, ASN1uint32_t tag, AlgorithmIdentifierNC2 *val)
  562. {
  563. ASN1decoding_t dd;
  564. ASN1octet_t *di;
  565. ASN1uint32_t t;
  566. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  567. return 0;
  568. ZeroMemory((val)->o, 1);
  569. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->algorithm))
  570. return 0;
  571. if (ASN1BERDecPeekTag(dd, &t)) {
  572. (val)->o[0] |= 0x80;
  573. if (!ASN1BERDecOpenType2(dd, &(val)->parameters))
  574. return 0;
  575. }
  576. if (!ASN1BERDecEndOfContents(dec, dd, di))
  577. return 0;
  578. return 1;
  579. }
  580. static void ASN1CALL ASN1Free_AlgorithmIdentifierNC2(AlgorithmIdentifierNC2 *val)
  581. {
  582. if (val) {
  583. if ((val)->o[0] & 0x80) {
  584. }
  585. }
  586. }
  587. static int ASN1CALL ASN1Enc_DigestAlgorithmIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, DigestAlgorithmIdentifier *val)
  588. {
  589. if (!ASN1Enc_AlgorithmIdentifier(enc, tag, val))
  590. return 0;
  591. return 1;
  592. }
  593. static int ASN1CALL ASN1Dec_DigestAlgorithmIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, DigestAlgorithmIdentifier *val)
  594. {
  595. if (!ASN1Dec_AlgorithmIdentifier(dec, tag, val))
  596. return 0;
  597. return 1;
  598. }
  599. static void ASN1CALL ASN1Free_DigestAlgorithmIdentifier(DigestAlgorithmIdentifier *val)
  600. {
  601. if (val) {
  602. ASN1Free_AlgorithmIdentifier(val);
  603. }
  604. }
  605. static int ASN1CALL ASN1Enc_AlgorithmIdentifiers(ASN1encoding_t enc, ASN1uint32_t tag, AlgorithmIdentifiers *val)
  606. {
  607. ASN1uint32_t nLenOff;
  608. void *pBlk;
  609. ASN1uint32_t i;
  610. ASN1encoding_t enc2;
  611. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  612. return 0;
  613. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  614. return 0;
  615. for (i = 0; i < (val)->count; i++) {
  616. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  617. return 0;
  618. if (!ASN1Enc_AlgorithmIdentifier(enc2, 0, &((val)->value)[i]))
  619. return 0;
  620. if (!ASN1DEREncFlushBlkElement(pBlk))
  621. return 0;
  622. }
  623. if (!ASN1DEREncEndBlk(pBlk))
  624. return 0;
  625. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  626. return 0;
  627. return 1;
  628. }
  629. static int ASN1CALL ASN1Dec_AlgorithmIdentifiers(ASN1decoding_t dec, ASN1uint32_t tag, AlgorithmIdentifiers *val)
  630. {
  631. ASN1decoding_t dd;
  632. ASN1octet_t *di;
  633. ASN1uint32_t t;
  634. ASN1uint32_t n;
  635. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  636. return 0;
  637. (val)->count = n = 0;
  638. (val)->value = NULL;
  639. while (ASN1BERDecNotEndOfContents(dd, di)) {
  640. if (!ASN1BERDecPeekTag(dd, &t))
  641. return 0;
  642. if ((val)->count >= n) {
  643. n = n ? (n << 1) : 16;
  644. if (!((val)->value = (AlgorithmIdentifier *)ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  645. return 0;
  646. }
  647. if (!ASN1Dec_AlgorithmIdentifier(dd, 0, &((val)->value)[(val)->count]))
  648. return 0;
  649. ((val)->count)++;
  650. }
  651. if (!ASN1BERDecEndOfContents(dec, dd, di))
  652. return 0;
  653. return 1;
  654. }
  655. static void ASN1CALL ASN1Free_AlgorithmIdentifiers(AlgorithmIdentifiers *val)
  656. {
  657. ASN1uint32_t i;
  658. if (val) {
  659. ASN1Free_AlgorithmIdentifier(&(val)->value[0]);
  660. for (i = 1; i < (val)->count; i++) {
  661. ASN1Free_AlgorithmIdentifier(&(val)->value[i]);
  662. }
  663. ASN1Free((val)->value);
  664. }
  665. }
  666. static int ASN1CALL ASN1Enc_AttributeSetValue(ASN1encoding_t enc, ASN1uint32_t tag, AttributeSetValue *val)
  667. {
  668. ASN1uint32_t nLenOff;
  669. void *pBlk;
  670. ASN1uint32_t i;
  671. ASN1encoding_t enc2;
  672. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  673. return 0;
  674. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  675. return 0;
  676. for (i = 0; i < (val)->count; i++) {
  677. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  678. return 0;
  679. if (!ASN1BEREncOpenType(enc2, &((val)->value)[i]))
  680. return 0;
  681. if (!ASN1DEREncFlushBlkElement(pBlk))
  682. return 0;
  683. }
  684. if (!ASN1DEREncEndBlk(pBlk))
  685. return 0;
  686. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  687. return 0;
  688. return 1;
  689. }
  690. static int ASN1CALL ASN1Dec_AttributeSetValue(ASN1decoding_t dec, ASN1uint32_t tag, AttributeSetValue *val)
  691. {
  692. ASN1decoding_t dd;
  693. ASN1octet_t *di;
  694. ASN1uint32_t t;
  695. ASN1uint32_t n;
  696. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  697. return 0;
  698. (val)->count = n = 0;
  699. (val)->value = NULL;
  700. while (ASN1BERDecNotEndOfContents(dd, di)) {
  701. if (!ASN1BERDecPeekTag(dd, &t))
  702. return 0;
  703. if ((val)->count >= n) {
  704. n = n ? (n << 1) : 16;
  705. if (!((val)->value = (AttributeSetValue_Set *)ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  706. return 0;
  707. }
  708. if (!ASN1BERDecOpenType(dd, &((val)->value)[(val)->count]))
  709. return 0;
  710. ((val)->count)++;
  711. }
  712. if (!ASN1BERDecEndOfContents(dec, dd, di))
  713. return 0;
  714. return 1;
  715. }
  716. static void ASN1CALL ASN1Free_AttributeSetValue(AttributeSetValue *val)
  717. {
  718. ASN1uint32_t i;
  719. if (val) {
  720. ASN1open_free(&(val)->value[0]);
  721. for (i = 1; i < (val)->count; i++) {
  722. ASN1open_free(&(val)->value[i]);
  723. }
  724. ASN1Free((val)->value);
  725. }
  726. }
  727. static int ASN1CALL ASN1Enc_AttributeSetValueNC(ASN1encoding_t enc, ASN1uint32_t tag, AttributeSetValueNC *val)
  728. {
  729. ASN1uint32_t nLenOff;
  730. void *pBlk;
  731. ASN1uint32_t i;
  732. ASN1encoding_t enc2;
  733. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  734. return 0;
  735. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  736. return 0;
  737. for (i = 0; i < (val)->count; i++) {
  738. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  739. return 0;
  740. if (!ASN1BEREncOpenType(enc2, &((val)->value)[i]))
  741. return 0;
  742. if (!ASN1DEREncFlushBlkElement(pBlk))
  743. return 0;
  744. }
  745. if (!ASN1DEREncEndBlk(pBlk))
  746. return 0;
  747. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  748. return 0;
  749. return 1;
  750. }
  751. static int ASN1CALL ASN1Dec_AttributeSetValueNC(ASN1decoding_t dec, ASN1uint32_t tag, AttributeSetValueNC *val)
  752. {
  753. ASN1decoding_t dd;
  754. ASN1octet_t *di;
  755. ASN1uint32_t t;
  756. ASN1uint32_t n;
  757. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  758. return 0;
  759. (val)->count = n = 0;
  760. (val)->value = NULL;
  761. while (ASN1BERDecNotEndOfContents(dd, di)) {
  762. if (!ASN1BERDecPeekTag(dd, &t))
  763. return 0;
  764. if ((val)->count >= n) {
  765. n = n ? (n << 1) : 16;
  766. if (!((val)->value = (AttributeSetValueNC_Set *)ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  767. return 0;
  768. }
  769. if (!ASN1BERDecOpenType2(dd, &((val)->value)[(val)->count]))
  770. return 0;
  771. ((val)->count)++;
  772. }
  773. if (!ASN1BERDecEndOfContents(dec, dd, di))
  774. return 0;
  775. return 1;
  776. }
  777. static void ASN1CALL ASN1Free_AttributeSetValueNC(AttributeSetValueNC *val)
  778. {
  779. ASN1uint32_t i;
  780. if (val) {
  781. for (i = 1; i < (val)->count; i++) {
  782. }
  783. ASN1Free((val)->value);
  784. }
  785. }
  786. static int ASN1CALL ASN1Enc_SetOfAny(ASN1encoding_t enc, ASN1uint32_t tag, SetOfAny *val)
  787. {
  788. ASN1uint32_t nLenOff;
  789. void *pBlk;
  790. ASN1uint32_t i;
  791. ASN1encoding_t enc2;
  792. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  793. return 0;
  794. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  795. return 0;
  796. for (i = 0; i < (val)->count; i++) {
  797. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  798. return 0;
  799. if (!ASN1BEREncOpenType(enc2, &((val)->value)[i]))
  800. return 0;
  801. if (!ASN1DEREncFlushBlkElement(pBlk))
  802. return 0;
  803. }
  804. if (!ASN1DEREncEndBlk(pBlk))
  805. return 0;
  806. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  807. return 0;
  808. return 1;
  809. }
  810. static int ASN1CALL ASN1Dec_SetOfAny(ASN1decoding_t dec, ASN1uint32_t tag, SetOfAny *val)
  811. {
  812. ASN1decoding_t dd;
  813. ASN1octet_t *di;
  814. ASN1uint32_t t;
  815. ASN1uint32_t n;
  816. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  817. return 0;
  818. (val)->count = n = 0;
  819. (val)->value = NULL;
  820. while (ASN1BERDecNotEndOfContents(dd, di)) {
  821. if (!ASN1BERDecPeekTag(dd, &t))
  822. return 0;
  823. if ((val)->count >= n) {
  824. n = n ? (n << 1) : 16;
  825. if (!((val)->value = (SetOfAny_Set *)ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  826. return 0;
  827. }
  828. if (!ASN1BERDecOpenType(dd, &((val)->value)[(val)->count]))
  829. return 0;
  830. ((val)->count)++;
  831. }
  832. if (!ASN1BERDecEndOfContents(dec, dd, di))
  833. return 0;
  834. return 1;
  835. }
  836. static void ASN1CALL ASN1Free_SetOfAny(SetOfAny *val)
  837. {
  838. ASN1uint32_t i;
  839. if (val) {
  840. ASN1open_free(&(val)->value[0]);
  841. for (i = 1; i < (val)->count; i++) {
  842. ASN1open_free(&(val)->value[i]);
  843. }
  844. ASN1Free((val)->value);
  845. }
  846. }
  847. static int ASN1CALL ASN1Enc_Attribute(ASN1encoding_t enc, ASN1uint32_t tag, Attribute *val)
  848. {
  849. ASN1uint32_t nLenOff;
  850. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  851. return 0;
  852. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->attributeType))
  853. return 0;
  854. if (!ASN1Enc_AttributeSetValue(enc, 0, &(val)->attributeValue))
  855. return 0;
  856. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  857. return 0;
  858. return 1;
  859. }
  860. static int ASN1CALL ASN1Dec_Attribute(ASN1decoding_t dec, ASN1uint32_t tag, Attribute *val)
  861. {
  862. ASN1decoding_t dd;
  863. ASN1octet_t *di;
  864. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  865. return 0;
  866. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->attributeType))
  867. return 0;
  868. if (!ASN1Dec_AttributeSetValue(dd, 0, &(val)->attributeValue))
  869. return 0;
  870. if (!ASN1BERDecEndOfContents(dec, dd, di))
  871. return 0;
  872. return 1;
  873. }
  874. static void ASN1CALL ASN1Free_Attribute(Attribute *val)
  875. {
  876. if (val) {
  877. ASN1Free_AttributeSetValue(&(val)->attributeValue);
  878. }
  879. }
  880. static int ASN1CALL ASN1Enc_AttributeNC2(ASN1encoding_t enc, ASN1uint32_t tag, AttributeNC2 *val)
  881. {
  882. ASN1uint32_t nLenOff;
  883. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  884. return 0;
  885. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->attributeType))
  886. return 0;
  887. if (!ASN1Enc_AttributeSetValueNC(enc, 0, &(val)->attributeValue))
  888. return 0;
  889. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  890. return 0;
  891. return 1;
  892. }
  893. static int ASN1CALL ASN1Dec_AttributeNC2(ASN1decoding_t dec, ASN1uint32_t tag, AttributeNC2 *val)
  894. {
  895. ASN1decoding_t dd;
  896. ASN1octet_t *di;
  897. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  898. return 0;
  899. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->attributeType))
  900. return 0;
  901. if (!ASN1Dec_AttributeSetValueNC(dd, 0, &(val)->attributeValue))
  902. return 0;
  903. if (!ASN1BERDecEndOfContents(dec, dd, di))
  904. return 0;
  905. return 1;
  906. }
  907. static void ASN1CALL ASN1Free_AttributeNC2(AttributeNC2 *val)
  908. {
  909. if (val) {
  910. ASN1Free_AttributeSetValueNC(&(val)->attributeValue);
  911. }
  912. }
  913. static int ASN1CALL ASN1Enc_Attributes(ASN1encoding_t enc, ASN1uint32_t tag, Attributes *val)
  914. {
  915. ASN1uint32_t nLenOff;
  916. void *pBlk;
  917. ASN1uint32_t i;
  918. ASN1encoding_t enc2;
  919. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  920. return 0;
  921. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  922. return 0;
  923. for (i = 0; i < (val)->count; i++) {
  924. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  925. return 0;
  926. if (!ASN1Enc_Attribute(enc2, 0, &((val)->value)[i]))
  927. return 0;
  928. if (!ASN1DEREncFlushBlkElement(pBlk))
  929. return 0;
  930. }
  931. if (!ASN1DEREncEndBlk(pBlk))
  932. return 0;
  933. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  934. return 0;
  935. return 1;
  936. }
  937. static int ASN1CALL ASN1Dec_Attributes(ASN1decoding_t dec, ASN1uint32_t tag, Attributes *val)
  938. {
  939. ASN1decoding_t dd;
  940. ASN1octet_t *di;
  941. ASN1uint32_t t;
  942. ASN1uint32_t n;
  943. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  944. return 0;
  945. (val)->count = n = 0;
  946. (val)->value = NULL;
  947. while (ASN1BERDecNotEndOfContents(dd, di)) {
  948. if (!ASN1BERDecPeekTag(dd, &t))
  949. return 0;
  950. if ((val)->count >= n) {
  951. n = n ? (n << 1) : 16;
  952. if (!((val)->value = (Attribute *)ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  953. return 0;
  954. }
  955. if (!ASN1Dec_Attribute(dd, 0, &((val)->value)[(val)->count]))
  956. return 0;
  957. ((val)->count)++;
  958. }
  959. if (!ASN1BERDecEndOfContents(dec, dd, di))
  960. return 0;
  961. return 1;
  962. }
  963. static void ASN1CALL ASN1Free_Attributes(Attributes *val)
  964. {
  965. ASN1uint32_t i;
  966. if (val) {
  967. ASN1Free_Attribute(&(val)->value[0]);
  968. for (i = 1; i < (val)->count; i++) {
  969. ASN1Free_Attribute(&(val)->value[i]);
  970. }
  971. ASN1Free((val)->value);
  972. }
  973. }
  974. static int ASN1CALL ASN1Enc_AttributesNC(ASN1encoding_t enc, ASN1uint32_t tag, AttributesNC *val)
  975. {
  976. ASN1uint32_t nLenOff;
  977. void *pBlk;
  978. ASN1uint32_t i;
  979. ASN1encoding_t enc2;
  980. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  981. return 0;
  982. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  983. return 0;
  984. for (i = 0; i < (val)->count; i++) {
  985. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  986. return 0;
  987. if (!ASN1BEREncOpenType(enc2, &((val)->value)[i]))
  988. return 0;
  989. if (!ASN1DEREncFlushBlkElement(pBlk))
  990. return 0;
  991. }
  992. if (!ASN1DEREncEndBlk(pBlk))
  993. return 0;
  994. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  995. return 0;
  996. return 1;
  997. }
  998. static int ASN1CALL ASN1Dec_AttributesNC(ASN1decoding_t dec, ASN1uint32_t tag, AttributesNC *val)
  999. {
  1000. ASN1decoding_t dd;
  1001. ASN1octet_t *di;
  1002. ASN1uint32_t t;
  1003. ASN1uint32_t n;
  1004. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  1005. return 0;
  1006. (val)->count = n = 0;
  1007. (val)->value = NULL;
  1008. while (ASN1BERDecNotEndOfContents(dd, di)) {
  1009. if (!ASN1BERDecPeekTag(dd, &t))
  1010. return 0;
  1011. if ((val)->count >= n) {
  1012. n = n ? (n << 1) : 16;
  1013. if (!((val)->value = (AttributeNC *)ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  1014. return 0;
  1015. }
  1016. if (!ASN1BERDecOpenType2(dd, &((val)->value)[(val)->count]))
  1017. return 0;
  1018. ((val)->count)++;
  1019. }
  1020. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1021. return 0;
  1022. return 1;
  1023. }
  1024. static void ASN1CALL ASN1Free_AttributesNC(AttributesNC *val)
  1025. {
  1026. ASN1uint32_t i;
  1027. if (val) {
  1028. for (i = 1; i < (val)->count; i++) {
  1029. }
  1030. ASN1Free((val)->value);
  1031. }
  1032. }
  1033. static int ASN1CALL ASN1Enc_AttributesNC2(ASN1encoding_t enc, ASN1uint32_t tag, AttributesNC2 *val)
  1034. {
  1035. ASN1uint32_t nLenOff;
  1036. void *pBlk;
  1037. ASN1uint32_t i;
  1038. ASN1encoding_t enc2;
  1039. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  1040. return 0;
  1041. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  1042. return 0;
  1043. for (i = 0; i < (val)->count; i++) {
  1044. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  1045. return 0;
  1046. if (!ASN1Enc_AttributeNC2(enc2, 0, &((val)->value)[i]))
  1047. return 0;
  1048. if (!ASN1DEREncFlushBlkElement(pBlk))
  1049. return 0;
  1050. }
  1051. if (!ASN1DEREncEndBlk(pBlk))
  1052. return 0;
  1053. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1054. return 0;
  1055. return 1;
  1056. }
  1057. static int ASN1CALL ASN1Dec_AttributesNC2(ASN1decoding_t dec, ASN1uint32_t tag, AttributesNC2 *val)
  1058. {
  1059. ASN1decoding_t dd;
  1060. ASN1octet_t *di;
  1061. ASN1uint32_t t;
  1062. ASN1uint32_t n;
  1063. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  1064. return 0;
  1065. (val)->count = n = 0;
  1066. (val)->value = NULL;
  1067. while (ASN1BERDecNotEndOfContents(dd, di)) {
  1068. if (!ASN1BERDecPeekTag(dd, &t))
  1069. return 0;
  1070. if ((val)->count >= n) {
  1071. n = n ? (n << 1) : 16;
  1072. if (!((val)->value = (AttributeNC2 *)ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  1073. return 0;
  1074. }
  1075. if (!ASN1Dec_AttributeNC2(dd, 0, &((val)->value)[(val)->count]))
  1076. return 0;
  1077. ((val)->count)++;
  1078. }
  1079. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1080. return 0;
  1081. return 1;
  1082. }
  1083. static void ASN1CALL ASN1Free_AttributesNC2(AttributesNC2 *val)
  1084. {
  1085. ASN1uint32_t i;
  1086. if (val) {
  1087. ASN1Free_AttributeNC2(&(val)->value[0]);
  1088. for (i = 1; i < (val)->count; i++) {
  1089. ASN1Free_AttributeNC2(&(val)->value[i]);
  1090. }
  1091. ASN1Free((val)->value);
  1092. }
  1093. }
  1094. static int ASN1CALL ASN1Enc_Crls(ASN1encoding_t enc, ASN1uint32_t tag, Crls *val)
  1095. {
  1096. ASN1uint32_t nLenOff;
  1097. void *pBlk;
  1098. ASN1uint32_t i;
  1099. ASN1encoding_t enc2;
  1100. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  1101. return 0;
  1102. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  1103. return 0;
  1104. for (i = 0; i < (val)->count; i++) {
  1105. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  1106. return 0;
  1107. if (!ASN1BEREncOpenType(enc2, &((val)->value)[i]))
  1108. return 0;
  1109. if (!ASN1DEREncFlushBlkElement(pBlk))
  1110. return 0;
  1111. }
  1112. if (!ASN1DEREncEndBlk(pBlk))
  1113. return 0;
  1114. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1115. return 0;
  1116. return 1;
  1117. }
  1118. static int ASN1CALL ASN1Dec_Crls(ASN1decoding_t dec, ASN1uint32_t tag, Crls *val)
  1119. {
  1120. ASN1decoding_t dd;
  1121. ASN1octet_t *di;
  1122. ASN1uint32_t t;
  1123. ASN1uint32_t n;
  1124. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  1125. return 0;
  1126. (val)->count = n = 0;
  1127. (val)->value = NULL;
  1128. while (ASN1BERDecNotEndOfContents(dd, di)) {
  1129. if (!ASN1BERDecPeekTag(dd, &t))
  1130. return 0;
  1131. if ((val)->count >= n) {
  1132. n = n ? (n << 1) : 16;
  1133. if (!((val)->value = (CertificateRevocationList *)ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  1134. return 0;
  1135. }
  1136. if (!ASN1BERDecOpenType(dd, &((val)->value)[(val)->count]))
  1137. return 0;
  1138. ((val)->count)++;
  1139. }
  1140. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1141. return 0;
  1142. return 1;
  1143. }
  1144. static void ASN1CALL ASN1Free_Crls(Crls *val)
  1145. {
  1146. ASN1uint32_t i;
  1147. if (val) {
  1148. ASN1open_free(&(val)->value[0]);
  1149. for (i = 1; i < (val)->count; i++) {
  1150. ASN1open_free(&(val)->value[i]);
  1151. }
  1152. ASN1Free((val)->value);
  1153. }
  1154. }
  1155. static int ASN1CALL ASN1Enc_CrlsNC(ASN1encoding_t enc, ASN1uint32_t tag, CrlsNC *val)
  1156. {
  1157. ASN1uint32_t nLenOff;
  1158. void *pBlk;
  1159. ASN1uint32_t i;
  1160. ASN1encoding_t enc2;
  1161. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  1162. return 0;
  1163. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  1164. return 0;
  1165. for (i = 0; i < (val)->count; i++) {
  1166. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  1167. return 0;
  1168. if (!ASN1BEREncOpenType(enc2, &((val)->value)[i]))
  1169. return 0;
  1170. if (!ASN1DEREncFlushBlkElement(pBlk))
  1171. return 0;
  1172. }
  1173. if (!ASN1DEREncEndBlk(pBlk))
  1174. return 0;
  1175. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1176. return 0;
  1177. return 1;
  1178. }
  1179. static int ASN1CALL ASN1Dec_CrlsNC(ASN1decoding_t dec, ASN1uint32_t tag, CrlsNC *val)
  1180. {
  1181. ASN1decoding_t dd;
  1182. ASN1octet_t *di;
  1183. ASN1uint32_t t;
  1184. ASN1uint32_t n;
  1185. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  1186. return 0;
  1187. (val)->count = n = 0;
  1188. (val)->value = NULL;
  1189. while (ASN1BERDecNotEndOfContents(dd, di)) {
  1190. if (!ASN1BERDecPeekTag(dd, &t))
  1191. return 0;
  1192. if ((val)->count >= n) {
  1193. n = n ? (n << 1) : 16;
  1194. if (!((val)->value = (CertificateRevocationListNC *)ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  1195. return 0;
  1196. }
  1197. if (!ASN1BERDecOpenType2(dd, &((val)->value)[(val)->count]))
  1198. return 0;
  1199. ((val)->count)++;
  1200. }
  1201. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1202. return 0;
  1203. return 1;
  1204. }
  1205. static void ASN1CALL ASN1Free_CrlsNC(CrlsNC *val)
  1206. {
  1207. ASN1uint32_t i;
  1208. if (val) {
  1209. for (i = 1; i < (val)->count; i++) {
  1210. }
  1211. ASN1Free((val)->value);
  1212. }
  1213. }
  1214. static int ASN1CALL ASN1Enc_ContentEncryptionAlgId(ASN1encoding_t enc, ASN1uint32_t tag, ContentEncryptionAlgId *val)
  1215. {
  1216. if (!ASN1Enc_AlgorithmIdentifier(enc, tag, val))
  1217. return 0;
  1218. return 1;
  1219. }
  1220. static int ASN1CALL ASN1Dec_ContentEncryptionAlgId(ASN1decoding_t dec, ASN1uint32_t tag, ContentEncryptionAlgId *val)
  1221. {
  1222. if (!ASN1Dec_AlgorithmIdentifier(dec, tag, val))
  1223. return 0;
  1224. return 1;
  1225. }
  1226. static void ASN1CALL ASN1Free_ContentEncryptionAlgId(ContentEncryptionAlgId *val)
  1227. {
  1228. if (val) {
  1229. ASN1Free_AlgorithmIdentifier(val);
  1230. }
  1231. }
  1232. static int ASN1CALL ASN1Enc_DigestEncryptionAlgId(ASN1encoding_t enc, ASN1uint32_t tag, DigestEncryptionAlgId *val)
  1233. {
  1234. if (!ASN1Enc_AlgorithmIdentifier(enc, tag, val))
  1235. return 0;
  1236. return 1;
  1237. }
  1238. static int ASN1CALL ASN1Dec_DigestEncryptionAlgId(ASN1decoding_t dec, ASN1uint32_t tag, DigestEncryptionAlgId *val)
  1239. {
  1240. if (!ASN1Dec_AlgorithmIdentifier(dec, tag, val))
  1241. return 0;
  1242. return 1;
  1243. }
  1244. static void ASN1CALL ASN1Free_DigestEncryptionAlgId(DigestEncryptionAlgId *val)
  1245. {
  1246. if (val) {
  1247. ASN1Free_AlgorithmIdentifier(val);
  1248. }
  1249. }
  1250. static int ASN1CALL ASN1Enc_DigestEncryptionAlgIdNC(ASN1encoding_t enc, ASN1uint32_t tag, DigestEncryptionAlgIdNC *val)
  1251. {
  1252. if (!ASN1Enc_AlgorithmIdentifierNC2(enc, tag, val))
  1253. return 0;
  1254. return 1;
  1255. }
  1256. static int ASN1CALL ASN1Dec_DigestEncryptionAlgIdNC(ASN1decoding_t dec, ASN1uint32_t tag, DigestEncryptionAlgIdNC *val)
  1257. {
  1258. if (!ASN1Dec_AlgorithmIdentifierNC2(dec, tag, val))
  1259. return 0;
  1260. return 1;
  1261. }
  1262. static void ASN1CALL ASN1Free_DigestEncryptionAlgIdNC(DigestEncryptionAlgIdNC *val)
  1263. {
  1264. if (val) {
  1265. ASN1Free_AlgorithmIdentifierNC2(val);
  1266. }
  1267. }
  1268. static int ASN1CALL ASN1Enc_Certificates(ASN1encoding_t enc, ASN1uint32_t tag, Certificates *val)
  1269. {
  1270. ASN1uint32_t nLenOff;
  1271. void *pBlk;
  1272. ASN1uint32_t i;
  1273. ASN1encoding_t enc2;
  1274. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  1275. return 0;
  1276. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  1277. return 0;
  1278. for (i = 0; i < (val)->count; i++) {
  1279. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  1280. return 0;
  1281. if (!ASN1BEREncOpenType(enc2, &((val)->value)[i]))
  1282. return 0;
  1283. if (!ASN1DEREncFlushBlkElement(pBlk))
  1284. return 0;
  1285. }
  1286. if (!ASN1DEREncEndBlk(pBlk))
  1287. return 0;
  1288. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1289. return 0;
  1290. return 1;
  1291. }
  1292. static int ASN1CALL ASN1Dec_Certificates(ASN1decoding_t dec, ASN1uint32_t tag, Certificates *val)
  1293. {
  1294. ASN1decoding_t dd;
  1295. ASN1octet_t *di;
  1296. ASN1uint32_t t;
  1297. ASN1uint32_t n;
  1298. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  1299. return 0;
  1300. (val)->count = n = 0;
  1301. (val)->value = NULL;
  1302. while (ASN1BERDecNotEndOfContents(dd, di)) {
  1303. if (!ASN1BERDecPeekTag(dd, &t))
  1304. return 0;
  1305. if ((val)->count >= n) {
  1306. n = n ? (n << 1) : 16;
  1307. if (!((val)->value = (Certificate *)ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  1308. return 0;
  1309. }
  1310. if (!ASN1BERDecOpenType(dd, &((val)->value)[(val)->count]))
  1311. return 0;
  1312. ((val)->count)++;
  1313. }
  1314. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1315. return 0;
  1316. return 1;
  1317. }
  1318. static void ASN1CALL ASN1Free_Certificates(Certificates *val)
  1319. {
  1320. ASN1uint32_t i;
  1321. if (val) {
  1322. ASN1open_free(&(val)->value[0]);
  1323. for (i = 1; i < (val)->count; i++) {
  1324. ASN1open_free(&(val)->value[i]);
  1325. }
  1326. ASN1Free((val)->value);
  1327. }
  1328. }
  1329. static int ASN1CALL ASN1Enc_CertificatesNC(ASN1encoding_t enc, ASN1uint32_t tag, CertificatesNC *val)
  1330. {
  1331. ASN1uint32_t nLenOff;
  1332. void *pBlk;
  1333. ASN1uint32_t i;
  1334. ASN1encoding_t enc2;
  1335. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  1336. return 0;
  1337. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  1338. return 0;
  1339. for (i = 0; i < (val)->count; i++) {
  1340. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  1341. return 0;
  1342. if (!ASN1BEREncOpenType(enc2, &((val)->value)[i]))
  1343. return 0;
  1344. if (!ASN1DEREncFlushBlkElement(pBlk))
  1345. return 0;
  1346. }
  1347. if (!ASN1DEREncEndBlk(pBlk))
  1348. return 0;
  1349. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1350. return 0;
  1351. return 1;
  1352. }
  1353. static int ASN1CALL ASN1Dec_CertificatesNC(ASN1decoding_t dec, ASN1uint32_t tag, CertificatesNC *val)
  1354. {
  1355. ASN1decoding_t dd;
  1356. ASN1octet_t *di;
  1357. ASN1uint32_t t;
  1358. ASN1uint32_t n;
  1359. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  1360. return 0;
  1361. (val)->count = n = 0;
  1362. (val)->value = NULL;
  1363. while (ASN1BERDecNotEndOfContents(dd, di)) {
  1364. if (!ASN1BERDecPeekTag(dd, &t))
  1365. return 0;
  1366. if ((val)->count >= n) {
  1367. n = n ? (n << 1) : 16;
  1368. if (!((val)->value = (CertificateNC *)ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  1369. return 0;
  1370. }
  1371. if (!ASN1BERDecOpenType2(dd, &((val)->value)[(val)->count]))
  1372. return 0;
  1373. ((val)->count)++;
  1374. }
  1375. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1376. return 0;
  1377. return 1;
  1378. }
  1379. static void ASN1CALL ASN1Free_CertificatesNC(CertificatesNC *val)
  1380. {
  1381. ASN1uint32_t i;
  1382. if (val) {
  1383. for (i = 1; i < (val)->count; i++) {
  1384. }
  1385. ASN1Free((val)->value);
  1386. }
  1387. }
  1388. static int ASN1CALL ASN1Enc_IssuerAndSerialNumber(ASN1encoding_t enc, ASN1uint32_t tag, IssuerAndSerialNumber *val)
  1389. {
  1390. ASN1uint32_t nLenOff;
  1391. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1392. return 0;
  1393. if (!ASN1BEREncOpenType(enc, &(val)->issuer))
  1394. return 0;
  1395. if (!ASN1BEREncSX(enc, 0x2, &(val)->serialNumber))
  1396. return 0;
  1397. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1398. return 0;
  1399. return 1;
  1400. }
  1401. static int ASN1CALL ASN1Dec_IssuerAndSerialNumber(ASN1decoding_t dec, ASN1uint32_t tag, IssuerAndSerialNumber *val)
  1402. {
  1403. ASN1decoding_t dd;
  1404. ASN1octet_t *di;
  1405. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1406. return 0;
  1407. if (!ASN1BERDecOpenType(dd, &(val)->issuer))
  1408. return 0;
  1409. if (!ASN1BERDecSXVal(dd, 0x2, &(val)->serialNumber))
  1410. return 0;
  1411. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1412. return 0;
  1413. return 1;
  1414. }
  1415. static void ASN1CALL ASN1Free_IssuerAndSerialNumber(IssuerAndSerialNumber *val)
  1416. {
  1417. if (val) {
  1418. ASN1open_free(&(val)->issuer);
  1419. ASN1intx_free(&(val)->serialNumber);
  1420. }
  1421. }
  1422. static int ASN1CALL ASN1Enc_KeyEncryptionAlgId(ASN1encoding_t enc, ASN1uint32_t tag, KeyEncryptionAlgId *val)
  1423. {
  1424. if (!ASN1Enc_AlgorithmIdentifier(enc, tag, val))
  1425. return 0;
  1426. return 1;
  1427. }
  1428. static int ASN1CALL ASN1Dec_KeyEncryptionAlgId(ASN1decoding_t dec, ASN1uint32_t tag, KeyEncryptionAlgId *val)
  1429. {
  1430. if (!ASN1Dec_AlgorithmIdentifier(dec, tag, val))
  1431. return 0;
  1432. return 1;
  1433. }
  1434. static void ASN1CALL ASN1Free_KeyEncryptionAlgId(KeyEncryptionAlgId *val)
  1435. {
  1436. if (val) {
  1437. ASN1Free_AlgorithmIdentifier(val);
  1438. }
  1439. }
  1440. static int ASN1CALL ASN1Enc_ContentInfo(ASN1encoding_t enc, ASN1uint32_t tag, ContentInfo *val)
  1441. {
  1442. ASN1uint32_t nLenOff;
  1443. ASN1uint32_t nLenOff0;
  1444. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1445. return 0;
  1446. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->contentType))
  1447. return 0;
  1448. if ((val)->o[0] & 0x80) {
  1449. if (!ASN1BEREncExplicitTag(enc, 0x80000000, &nLenOff0))
  1450. return 0;
  1451. if (!ASN1BEREncOpenType(enc, &(val)->content))
  1452. return 0;
  1453. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  1454. return 0;
  1455. }
  1456. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1457. return 0;
  1458. return 1;
  1459. }
  1460. static int ASN1CALL ASN1Dec_ContentInfo(ASN1decoding_t dec, ASN1uint32_t tag, ContentInfo *val)
  1461. {
  1462. ASN1decoding_t dd;
  1463. ASN1octet_t *di;
  1464. ASN1uint32_t t;
  1465. ASN1decoding_t dd0;
  1466. ASN1octet_t *di0;
  1467. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1468. return 0;
  1469. ZeroMemory((val)->o, 1);
  1470. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->contentType))
  1471. return 0;
  1472. if (ASN1BERDecPeekTag(dd, &t)) {
  1473. if (t == 0x80000000) {
  1474. (val)->o[0] |= 0x80;
  1475. if (!ASN1BERDecExplicitTag(dd, 0x80000000, &dd0, &di0))
  1476. return 0;
  1477. if (!ASN1BERDecOpenType(dd0, &(val)->content))
  1478. return 0;
  1479. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  1480. return 0;
  1481. }
  1482. }
  1483. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1484. return 0;
  1485. return 1;
  1486. }
  1487. static void ASN1CALL ASN1Free_ContentInfo(ContentInfo *val)
  1488. {
  1489. if (val) {
  1490. if ((val)->o[0] & 0x80) {
  1491. ASN1open_free(&(val)->content);
  1492. }
  1493. }
  1494. }
  1495. static int ASN1CALL ASN1Enc_ContentInfoNC(ASN1encoding_t enc, ASN1uint32_t tag, ContentInfoNC *val)
  1496. {
  1497. ASN1uint32_t nLenOff;
  1498. ASN1uint32_t nLenOff0;
  1499. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1500. return 0;
  1501. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->contentType))
  1502. return 0;
  1503. if ((val)->o[0] & 0x80) {
  1504. if (!ASN1BEREncExplicitTag(enc, 0x80000000, &nLenOff0))
  1505. return 0;
  1506. if (!ASN1BEREncOpenType(enc, &(val)->content))
  1507. return 0;
  1508. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  1509. return 0;
  1510. }
  1511. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1512. return 0;
  1513. return 1;
  1514. }
  1515. static int ASN1CALL ASN1Dec_ContentInfoNC(ASN1decoding_t dec, ASN1uint32_t tag, ContentInfoNC *val)
  1516. {
  1517. ASN1decoding_t dd;
  1518. ASN1octet_t *di;
  1519. ASN1uint32_t t;
  1520. ASN1decoding_t dd0;
  1521. ASN1octet_t *di0;
  1522. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1523. return 0;
  1524. ZeroMemory((val)->o, 1);
  1525. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->contentType))
  1526. return 0;
  1527. if (ASN1BERDecPeekTag(dd, &t)) {
  1528. if (t == 0x80000000) {
  1529. (val)->o[0] |= 0x80;
  1530. if (!ASN1BERDecExplicitTag(dd, 0x80000000, &dd0, &di0))
  1531. return 0;
  1532. if (!ASN1BERDecOpenType2(dd0, &(val)->content))
  1533. return 0;
  1534. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  1535. return 0;
  1536. }
  1537. }
  1538. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1539. return 0;
  1540. return 1;
  1541. }
  1542. static void ASN1CALL ASN1Free_ContentInfoNC(ContentInfoNC *val)
  1543. {
  1544. if (val) {
  1545. if ((val)->o[0] & 0x80) {
  1546. }
  1547. }
  1548. }
  1549. static int ASN1CALL ASN1Enc_DigestAlgorithmIdentifiers(ASN1encoding_t enc, ASN1uint32_t tag, DigestAlgorithmIdentifiers *val)
  1550. {
  1551. ASN1uint32_t nLenOff;
  1552. void *pBlk;
  1553. ASN1uint32_t i;
  1554. ASN1encoding_t enc2;
  1555. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  1556. return 0;
  1557. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  1558. return 0;
  1559. for (i = 0; i < (val)->count; i++) {
  1560. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  1561. return 0;
  1562. if (!ASN1Enc_DigestAlgorithmIdentifier(enc2, 0, &((val)->value)[i]))
  1563. return 0;
  1564. if (!ASN1DEREncFlushBlkElement(pBlk))
  1565. return 0;
  1566. }
  1567. if (!ASN1DEREncEndBlk(pBlk))
  1568. return 0;
  1569. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1570. return 0;
  1571. return 1;
  1572. }
  1573. static int ASN1CALL ASN1Dec_DigestAlgorithmIdentifiers(ASN1decoding_t dec, ASN1uint32_t tag, DigestAlgorithmIdentifiers *val)
  1574. {
  1575. ASN1decoding_t dd;
  1576. ASN1octet_t *di;
  1577. ASN1uint32_t t;
  1578. ASN1uint32_t n;
  1579. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  1580. return 0;
  1581. (val)->count = n = 0;
  1582. (val)->value = NULL;
  1583. while (ASN1BERDecNotEndOfContents(dd, di)) {
  1584. if (!ASN1BERDecPeekTag(dd, &t))
  1585. return 0;
  1586. if ((val)->count >= n) {
  1587. n = n ? (n << 1) : 16;
  1588. if (!((val)->value = (DigestAlgorithmIdentifier *)ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  1589. return 0;
  1590. }
  1591. if (!ASN1Dec_DigestAlgorithmIdentifier(dd, 0, &((val)->value)[(val)->count]))
  1592. return 0;
  1593. ((val)->count)++;
  1594. }
  1595. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1596. return 0;
  1597. return 1;
  1598. }
  1599. static void ASN1CALL ASN1Free_DigestAlgorithmIdentifiers(DigestAlgorithmIdentifiers *val)
  1600. {
  1601. ASN1uint32_t i;
  1602. if (val) {
  1603. ASN1Free_DigestAlgorithmIdentifier(&(val)->value[0]);
  1604. for (i = 1; i < (val)->count; i++) {
  1605. ASN1Free_DigestAlgorithmIdentifier(&(val)->value[i]);
  1606. }
  1607. ASN1Free((val)->value);
  1608. }
  1609. }
  1610. static int ASN1CALL ASN1Enc_DigestAlgorithmIdentifiersNC(ASN1encoding_t enc, ASN1uint32_t tag, DigestAlgorithmIdentifiersNC *val)
  1611. {
  1612. ASN1uint32_t nLenOff;
  1613. void *pBlk;
  1614. ASN1uint32_t i;
  1615. ASN1encoding_t enc2;
  1616. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  1617. return 0;
  1618. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  1619. return 0;
  1620. for (i = 0; i < (val)->count; i++) {
  1621. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  1622. return 0;
  1623. if (!ASN1BEREncOpenType(enc2, &((val)->value)[i]))
  1624. return 0;
  1625. if (!ASN1DEREncFlushBlkElement(pBlk))
  1626. return 0;
  1627. }
  1628. if (!ASN1DEREncEndBlk(pBlk))
  1629. return 0;
  1630. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1631. return 0;
  1632. return 1;
  1633. }
  1634. static int ASN1CALL ASN1Dec_DigestAlgorithmIdentifiersNC(ASN1decoding_t dec, ASN1uint32_t tag, DigestAlgorithmIdentifiersNC *val)
  1635. {
  1636. ASN1decoding_t dd;
  1637. ASN1octet_t *di;
  1638. ASN1uint32_t t;
  1639. ASN1uint32_t n;
  1640. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  1641. return 0;
  1642. (val)->count = n = 0;
  1643. (val)->value = NULL;
  1644. while (ASN1BERDecNotEndOfContents(dd, di)) {
  1645. if (!ASN1BERDecPeekTag(dd, &t))
  1646. return 0;
  1647. if ((val)->count >= n) {
  1648. n = n ? (n << 1) : 16;
  1649. if (!((val)->value = (DigestAlgorithmIdentifierNC *)ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  1650. return 0;
  1651. }
  1652. if (!ASN1BERDecOpenType2(dd, &((val)->value)[(val)->count]))
  1653. return 0;
  1654. ((val)->count)++;
  1655. }
  1656. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1657. return 0;
  1658. return 1;
  1659. }
  1660. static void ASN1CALL ASN1Free_DigestAlgorithmIdentifiersNC(DigestAlgorithmIdentifiersNC *val)
  1661. {
  1662. ASN1uint32_t i;
  1663. if (val) {
  1664. for (i = 1; i < (val)->count; i++) {
  1665. }
  1666. ASN1Free((val)->value);
  1667. }
  1668. }
  1669. static int ASN1CALL ASN1Enc_SignerInfos(ASN1encoding_t enc, ASN1uint32_t tag, SignerInfos *val)
  1670. {
  1671. ASN1uint32_t nLenOff;
  1672. void *pBlk;
  1673. ASN1uint32_t i;
  1674. ASN1encoding_t enc2;
  1675. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  1676. return 0;
  1677. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  1678. return 0;
  1679. for (i = 0; i < (val)->count; i++) {
  1680. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  1681. return 0;
  1682. if (!ASN1Enc_SignerInfo(enc2, 0, &((val)->value)[i]))
  1683. return 0;
  1684. if (!ASN1DEREncFlushBlkElement(pBlk))
  1685. return 0;
  1686. }
  1687. if (!ASN1DEREncEndBlk(pBlk))
  1688. return 0;
  1689. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1690. return 0;
  1691. return 1;
  1692. }
  1693. static int ASN1CALL ASN1Dec_SignerInfos(ASN1decoding_t dec, ASN1uint32_t tag, SignerInfos *val)
  1694. {
  1695. ASN1decoding_t dd;
  1696. ASN1octet_t *di;
  1697. ASN1uint32_t t;
  1698. ASN1uint32_t n;
  1699. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  1700. return 0;
  1701. (val)->count = n = 0;
  1702. (val)->value = NULL;
  1703. while (ASN1BERDecNotEndOfContents(dd, di)) {
  1704. if (!ASN1BERDecPeekTag(dd, &t))
  1705. return 0;
  1706. if ((val)->count >= n) {
  1707. n = n ? (n << 1) : 16;
  1708. if (!((val)->value = (SignerInfo *)ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  1709. return 0;
  1710. }
  1711. if (!ASN1Dec_SignerInfo(dd, 0, &((val)->value)[(val)->count]))
  1712. return 0;
  1713. ((val)->count)++;
  1714. }
  1715. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1716. return 0;
  1717. return 1;
  1718. }
  1719. static void ASN1CALL ASN1Free_SignerInfos(SignerInfos *val)
  1720. {
  1721. ASN1uint32_t i;
  1722. if (val) {
  1723. ASN1Free_SignerInfo(&(val)->value[0]);
  1724. for (i = 1; i < (val)->count; i++) {
  1725. ASN1Free_SignerInfo(&(val)->value[i]);
  1726. }
  1727. ASN1Free((val)->value);
  1728. }
  1729. }
  1730. static int ASN1CALL ASN1Enc_DigestAlgorithmBlobs(ASN1encoding_t enc, ASN1uint32_t tag, DigestAlgorithmBlobs *val)
  1731. {
  1732. ASN1uint32_t nLenOff;
  1733. void *pBlk;
  1734. ASN1uint32_t i;
  1735. ASN1encoding_t enc2;
  1736. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  1737. return 0;
  1738. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  1739. return 0;
  1740. for (i = 0; i < (val)->count; i++) {
  1741. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  1742. return 0;
  1743. if (!ASN1BEREncOpenType(enc2, &((val)->value)[i]))
  1744. return 0;
  1745. if (!ASN1DEREncFlushBlkElement(pBlk))
  1746. return 0;
  1747. }
  1748. if (!ASN1DEREncEndBlk(pBlk))
  1749. return 0;
  1750. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1751. return 0;
  1752. return 1;
  1753. }
  1754. static int ASN1CALL ASN1Dec_DigestAlgorithmBlobs(ASN1decoding_t dec, ASN1uint32_t tag, DigestAlgorithmBlobs *val)
  1755. {
  1756. ASN1decoding_t dd;
  1757. ASN1octet_t *di;
  1758. ASN1uint32_t t;
  1759. ASN1uint32_t n;
  1760. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  1761. return 0;
  1762. (val)->count = n = 0;
  1763. (val)->value = NULL;
  1764. while (ASN1BERDecNotEndOfContents(dd, di)) {
  1765. if (!ASN1BERDecPeekTag(dd, &t))
  1766. return 0;
  1767. if ((val)->count >= n) {
  1768. n = n ? (n << 1) : 16;
  1769. if (!((val)->value = (DigestAlgorithmBlob *)ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  1770. return 0;
  1771. }
  1772. if (!ASN1BERDecOpenType2(dd, &((val)->value)[(val)->count]))
  1773. return 0;
  1774. ((val)->count)++;
  1775. }
  1776. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1777. return 0;
  1778. return 1;
  1779. }
  1780. static void ASN1CALL ASN1Free_DigestAlgorithmBlobs(DigestAlgorithmBlobs *val)
  1781. {
  1782. ASN1uint32_t i;
  1783. if (val) {
  1784. for (i = 1; i < (val)->count; i++) {
  1785. }
  1786. ASN1Free((val)->value);
  1787. }
  1788. }
  1789. static int ASN1CALL ASN1Enc_SignerInfosNC(ASN1encoding_t enc, ASN1uint32_t tag, SignerInfosNC *val)
  1790. {
  1791. ASN1uint32_t nLenOff;
  1792. void *pBlk;
  1793. ASN1uint32_t i;
  1794. ASN1encoding_t enc2;
  1795. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  1796. return 0;
  1797. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  1798. return 0;
  1799. for (i = 0; i < (val)->count; i++) {
  1800. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  1801. return 0;
  1802. if (!ASN1BEREncOpenType(enc2, &((val)->value)[i]))
  1803. return 0;
  1804. if (!ASN1DEREncFlushBlkElement(pBlk))
  1805. return 0;
  1806. }
  1807. if (!ASN1DEREncEndBlk(pBlk))
  1808. return 0;
  1809. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1810. return 0;
  1811. return 1;
  1812. }
  1813. static int ASN1CALL ASN1Dec_SignerInfosNC(ASN1decoding_t dec, ASN1uint32_t tag, SignerInfosNC *val)
  1814. {
  1815. ASN1decoding_t dd;
  1816. ASN1octet_t *di;
  1817. ASN1uint32_t t;
  1818. ASN1uint32_t n;
  1819. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  1820. return 0;
  1821. (val)->count = n = 0;
  1822. (val)->value = NULL;
  1823. while (ASN1BERDecNotEndOfContents(dd, di)) {
  1824. if (!ASN1BERDecPeekTag(dd, &t))
  1825. return 0;
  1826. if ((val)->count >= n) {
  1827. n = n ? (n << 1) : 16;
  1828. if (!((val)->value = (SignerInfosNC_Set *)ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  1829. return 0;
  1830. }
  1831. if (!ASN1BERDecOpenType2(dd, &((val)->value)[(val)->count]))
  1832. return 0;
  1833. ((val)->count)++;
  1834. }
  1835. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1836. return 0;
  1837. return 1;
  1838. }
  1839. static void ASN1CALL ASN1Free_SignerInfosNC(SignerInfosNC *val)
  1840. {
  1841. ASN1uint32_t i;
  1842. if (val) {
  1843. for (i = 1; i < (val)->count; i++) {
  1844. }
  1845. ASN1Free((val)->value);
  1846. }
  1847. }
  1848. static int ASN1CALL ASN1Enc_SignerInfoWithAABlobs(ASN1encoding_t enc, ASN1uint32_t tag, SignerInfoWithAABlobs *val)
  1849. {
  1850. ASN1uint32_t nLenOff;
  1851. void *pBlk;
  1852. ASN1uint32_t i;
  1853. ASN1encoding_t enc2;
  1854. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  1855. return 0;
  1856. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  1857. return 0;
  1858. for (i = 0; i < (val)->count; i++) {
  1859. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  1860. return 0;
  1861. if (!ASN1Enc_SignerInfoWithAABlob(enc2, 0, &((val)->value)[i]))
  1862. return 0;
  1863. if (!ASN1DEREncFlushBlkElement(pBlk))
  1864. return 0;
  1865. }
  1866. if (!ASN1DEREncEndBlk(pBlk))
  1867. return 0;
  1868. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1869. return 0;
  1870. return 1;
  1871. }
  1872. static int ASN1CALL ASN1Dec_SignerInfoWithAABlobs(ASN1decoding_t dec, ASN1uint32_t tag, SignerInfoWithAABlobs *val)
  1873. {
  1874. ASN1decoding_t dd;
  1875. ASN1octet_t *di;
  1876. ASN1uint32_t t;
  1877. ASN1uint32_t n;
  1878. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  1879. return 0;
  1880. (val)->count = n = 0;
  1881. (val)->value = NULL;
  1882. while (ASN1BERDecNotEndOfContents(dd, di)) {
  1883. if (!ASN1BERDecPeekTag(dd, &t))
  1884. return 0;
  1885. if ((val)->count >= n) {
  1886. n = n ? (n << 1) : 16;
  1887. if (!((val)->value = (SignerInfoWithAABlob *)ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  1888. return 0;
  1889. }
  1890. if (!ASN1Dec_SignerInfoWithAABlob(dd, 0, &((val)->value)[(val)->count]))
  1891. return 0;
  1892. ((val)->count)++;
  1893. }
  1894. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1895. return 0;
  1896. return 1;
  1897. }
  1898. static void ASN1CALL ASN1Free_SignerInfoWithAABlobs(SignerInfoWithAABlobs *val)
  1899. {
  1900. ASN1uint32_t i;
  1901. if (val) {
  1902. ASN1Free_SignerInfoWithAABlob(&(val)->value[0]);
  1903. for (i = 1; i < (val)->count; i++) {
  1904. ASN1Free_SignerInfoWithAABlob(&(val)->value[i]);
  1905. }
  1906. ASN1Free((val)->value);
  1907. }
  1908. }
  1909. static int ASN1CALL ASN1Enc_SignerInfoWithAABlob(ASN1encoding_t enc, ASN1uint32_t tag, SignerInfoWithAABlob *val)
  1910. {
  1911. ASN1uint32_t nLenOff;
  1912. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1913. return 0;
  1914. if (!ASN1BEREncOpenType(enc, &(val)->version))
  1915. return 0;
  1916. if (!ASN1BEREncOpenType(enc, &(val)->sid))
  1917. return 0;
  1918. if (!ASN1BEREncOpenType(enc, &(val)->digestAlgorithm))
  1919. return 0;
  1920. if (!ASN1BEREncOpenType(enc, &(val)->authenticatedAttributes))
  1921. return 0;
  1922. if (!ASN1BEREncOpenType(enc, &(val)->digestEncryptionAlgorithm))
  1923. return 0;
  1924. if (!ASN1BEREncOpenType(enc, &(val)->encryptedDigest))
  1925. return 0;
  1926. if ((val)->o[0] & 0x80) {
  1927. if (!ASN1Enc_AttributesNC(enc, 0x80000001, &(val)->dummyUAAs))
  1928. return 0;
  1929. }
  1930. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1931. return 0;
  1932. return 1;
  1933. }
  1934. static int ASN1CALL ASN1Dec_SignerInfoWithAABlob(ASN1decoding_t dec, ASN1uint32_t tag, SignerInfoWithAABlob *val)
  1935. {
  1936. ASN1decoding_t dd;
  1937. ASN1octet_t *di;
  1938. ASN1uint32_t t;
  1939. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1940. return 0;
  1941. ZeroMemory((val)->o, 1);
  1942. if (!ASN1BERDecOpenType2(dd, &(val)->version))
  1943. return 0;
  1944. if (!ASN1BERDecOpenType2(dd, &(val)->sid))
  1945. return 0;
  1946. if (!ASN1BERDecOpenType2(dd, &(val)->digestAlgorithm))
  1947. return 0;
  1948. if (!ASN1BERDecOpenType2(dd, &(val)->authenticatedAttributes))
  1949. return 0;
  1950. if (!ASN1BERDecOpenType2(dd, &(val)->digestEncryptionAlgorithm))
  1951. return 0;
  1952. if (!ASN1BERDecOpenType2(dd, &(val)->encryptedDigest))
  1953. return 0;
  1954. ASN1BERDecPeekTag(dd, &t);
  1955. if (t == 0x80000001) {
  1956. (val)->o[0] |= 0x80;
  1957. if (!ASN1Dec_AttributesNC(dd, 0x80000001, &(val)->dummyUAAs))
  1958. return 0;
  1959. }
  1960. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1961. return 0;
  1962. return 1;
  1963. }
  1964. static void ASN1CALL ASN1Free_SignerInfoWithAABlob(SignerInfoWithAABlob *val)
  1965. {
  1966. if (val) {
  1967. if ((val)->o[0] & 0x80) {
  1968. ASN1Free_AttributesNC(&(val)->dummyUAAs);
  1969. }
  1970. }
  1971. }
  1972. static int ASN1CALL ASN1Enc_SignerInfoWithAttrBlobs(ASN1encoding_t enc, ASN1uint32_t tag, SignerInfoWithAttrBlobs *val)
  1973. {
  1974. ASN1uint32_t nLenOff;
  1975. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1976. return 0;
  1977. if (!ASN1BEREncOpenType(enc, &(val)->version))
  1978. return 0;
  1979. if (!ASN1BEREncOpenType(enc, &(val)->sid))
  1980. return 0;
  1981. if (!ASN1BEREncOpenType(enc, &(val)->digestAlgorithm))
  1982. return 0;
  1983. if ((val)->o[0] & 0x80) {
  1984. if (!ASN1Enc_AttributesNC(enc, 0x80000000, &(val)->authAttributes))
  1985. return 0;
  1986. }
  1987. if (!ASN1Enc_DigestEncryptionAlgIdNC(enc, 0, &(val)->digestEncryptionAlgorithm))
  1988. return 0;
  1989. if (!ASN1BEREncOpenType(enc, &(val)->encryptedDigest))
  1990. return 0;
  1991. if ((val)->o[0] & 0x40) {
  1992. if (!ASN1Enc_AttributesNC(enc, 0x80000001, &(val)->unauthAttributes))
  1993. return 0;
  1994. }
  1995. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1996. return 0;
  1997. return 1;
  1998. }
  1999. static int ASN1CALL ASN1Dec_SignerInfoWithAttrBlobs(ASN1decoding_t dec, ASN1uint32_t tag, SignerInfoWithAttrBlobs *val)
  2000. {
  2001. ASN1decoding_t dd;
  2002. ASN1octet_t *di;
  2003. ASN1uint32_t t;
  2004. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  2005. return 0;
  2006. ZeroMemory((val)->o, 1);
  2007. if (!ASN1BERDecOpenType2(dd, &(val)->version))
  2008. return 0;
  2009. if (!ASN1BERDecOpenType2(dd, &(val)->sid))
  2010. return 0;
  2011. if (!ASN1BERDecOpenType2(dd, &(val)->digestAlgorithm))
  2012. return 0;
  2013. ASN1BERDecPeekTag(dd, &t);
  2014. if (t == 0x80000000) {
  2015. (val)->o[0] |= 0x80;
  2016. if (!ASN1Dec_AttributesNC(dd, 0x80000000, &(val)->authAttributes))
  2017. return 0;
  2018. }
  2019. if (!ASN1Dec_DigestEncryptionAlgIdNC(dd, 0, &(val)->digestEncryptionAlgorithm))
  2020. return 0;
  2021. if (!ASN1BERDecOpenType2(dd, &(val)->encryptedDigest))
  2022. return 0;
  2023. ASN1BERDecPeekTag(dd, &t);
  2024. if (t == 0x80000001) {
  2025. (val)->o[0] |= 0x40;
  2026. if (!ASN1Dec_AttributesNC(dd, 0x80000001, &(val)->unauthAttributes))
  2027. return 0;
  2028. }
  2029. if (!ASN1BERDecEndOfContents(dec, dd, di))
  2030. return 0;
  2031. return 1;
  2032. }
  2033. static void ASN1CALL ASN1Free_SignerInfoWithAttrBlobs(SignerInfoWithAttrBlobs *val)
  2034. {
  2035. if (val) {
  2036. if ((val)->o[0] & 0x80) {
  2037. ASN1Free_AttributesNC(&(val)->authAttributes);
  2038. }
  2039. ASN1Free_DigestEncryptionAlgIdNC(&(val)->digestEncryptionAlgorithm);
  2040. if ((val)->o[0] & 0x40) {
  2041. ASN1Free_AttributesNC(&(val)->unauthAttributes);
  2042. }
  2043. }
  2044. }
  2045. static int ASN1CALL ASN1Enc_SignerInfoWithBlobs(ASN1encoding_t enc, ASN1uint32_t tag, SignerInfoWithBlobs *val)
  2046. {
  2047. ASN1uint32_t nLenOff;
  2048. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  2049. return 0;
  2050. if (!ASN1BEREncS32(enc, 0x2, (val)->version))
  2051. return 0;
  2052. if (!ASN1BEREncOpenType(enc, &(val)->sid))
  2053. return 0;
  2054. if (!ASN1BEREncOpenType(enc, &(val)->digestAlgorithm))
  2055. return 0;
  2056. if ((val)->o[0] & 0x80) {
  2057. if (!ASN1Enc_AttributesNC2(enc, 0x80000000, &(val)->authAttributes))
  2058. return 0;
  2059. }
  2060. if (!ASN1Enc_DigestEncryptionAlgIdNC(enc, 0, &(val)->digestEncryptionAlgorithm))
  2061. return 0;
  2062. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->encryptedDigest).length, ((val)->encryptedDigest).value))
  2063. return 0;
  2064. if ((val)->o[0] & 0x40) {
  2065. if (!ASN1Enc_AttributesNC2(enc, 0x80000001, &(val)->unauthAttributes))
  2066. return 0;
  2067. }
  2068. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  2069. return 0;
  2070. return 1;
  2071. }
  2072. static int ASN1CALL ASN1Dec_SignerInfoWithBlobs(ASN1decoding_t dec, ASN1uint32_t tag, SignerInfoWithBlobs *val)
  2073. {
  2074. ASN1decoding_t dd;
  2075. ASN1octet_t *di;
  2076. ASN1uint32_t t;
  2077. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  2078. return 0;
  2079. ZeroMemory((val)->o, 1);
  2080. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->version))
  2081. return 0;
  2082. if (!ASN1BERDecOpenType2(dd, &(val)->sid))
  2083. return 0;
  2084. if (!ASN1BERDecOpenType2(dd, &(val)->digestAlgorithm))
  2085. return 0;
  2086. ASN1BERDecPeekTag(dd, &t);
  2087. if (t == 0x80000000) {
  2088. (val)->o[0] |= 0x80;
  2089. if (!ASN1Dec_AttributesNC2(dd, 0x80000000, &(val)->authAttributes))
  2090. return 0;
  2091. }
  2092. if (!ASN1Dec_DigestEncryptionAlgIdNC(dd, 0, &(val)->digestEncryptionAlgorithm))
  2093. return 0;
  2094. if (!ASN1BERDecOctetString2(dd, 0x4, &(val)->encryptedDigest))
  2095. return 0;
  2096. ASN1BERDecPeekTag(dd, &t);
  2097. if (t == 0x80000001) {
  2098. (val)->o[0] |= 0x40;
  2099. if (!ASN1Dec_AttributesNC2(dd, 0x80000001, &(val)->unauthAttributes))
  2100. return 0;
  2101. }
  2102. if (!ASN1BERDecEndOfContents(dec, dd, di))
  2103. return 0;
  2104. return 1;
  2105. }
  2106. static void ASN1CALL ASN1Free_SignerInfoWithBlobs(SignerInfoWithBlobs *val)
  2107. {
  2108. if (val) {
  2109. if ((val)->o[0] & 0x80) {
  2110. ASN1Free_AttributesNC2(&(val)->authAttributes);
  2111. }
  2112. ASN1Free_DigestEncryptionAlgIdNC(&(val)->digestEncryptionAlgorithm);
  2113. if ((val)->o[0] & 0x40) {
  2114. ASN1Free_AttributesNC2(&(val)->unauthAttributes);
  2115. }
  2116. }
  2117. }
  2118. static int ASN1CALL ASN1Enc_RecipientInfos(ASN1encoding_t enc, ASN1uint32_t tag, RecipientInfos *val)
  2119. {
  2120. ASN1uint32_t nLenOff;
  2121. void *pBlk;
  2122. ASN1uint32_t i;
  2123. ASN1encoding_t enc2;
  2124. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  2125. return 0;
  2126. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  2127. return 0;
  2128. for (i = 0; i < (val)->count; i++) {
  2129. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  2130. return 0;
  2131. if (!ASN1Enc_RecipientInfo(enc2, 0, &((val)->value)[i]))
  2132. return 0;
  2133. if (!ASN1DEREncFlushBlkElement(pBlk))
  2134. return 0;
  2135. }
  2136. if (!ASN1DEREncEndBlk(pBlk))
  2137. return 0;
  2138. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  2139. return 0;
  2140. return 1;
  2141. }
  2142. static int ASN1CALL ASN1Dec_RecipientInfos(ASN1decoding_t dec, ASN1uint32_t tag, RecipientInfos *val)
  2143. {
  2144. ASN1decoding_t dd;
  2145. ASN1octet_t *di;
  2146. ASN1uint32_t t;
  2147. ASN1uint32_t n;
  2148. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  2149. return 0;
  2150. (val)->count = n = 0;
  2151. (val)->value = NULL;
  2152. while (ASN1BERDecNotEndOfContents(dd, di)) {
  2153. if (!ASN1BERDecPeekTag(dd, &t))
  2154. return 0;
  2155. if ((val)->count >= n) {
  2156. n = n ? (n << 1) : 16;
  2157. if (!((val)->value = (RecipientInfo *)ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  2158. return 0;
  2159. }
  2160. if (!ASN1Dec_RecipientInfo(dd, 0, &((val)->value)[(val)->count]))
  2161. return 0;
  2162. ((val)->count)++;
  2163. }
  2164. if (!ASN1BERDecEndOfContents(dec, dd, di))
  2165. return 0;
  2166. return 1;
  2167. }
  2168. static void ASN1CALL ASN1Free_RecipientInfos(RecipientInfos *val)
  2169. {
  2170. ASN1uint32_t i;
  2171. if (val) {
  2172. ASN1Free_RecipientInfo(&(val)->value[0]);
  2173. for (i = 1; i < (val)->count; i++) {
  2174. ASN1Free_RecipientInfo(&(val)->value[i]);
  2175. }
  2176. ASN1Free((val)->value);
  2177. }
  2178. }
  2179. static int ASN1CALL ASN1Enc_EncryptedContentInfo(ASN1encoding_t enc, ASN1uint32_t tag, EncryptedContentInfo *val)
  2180. {
  2181. ASN1uint32_t nLenOff;
  2182. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  2183. return 0;
  2184. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->contentType))
  2185. return 0;
  2186. if (!ASN1Enc_ContentEncryptionAlgId(enc, 0, &(val)->contentEncryptionAlgorithm))
  2187. return 0;
  2188. if ((val)->o[0] & 0x80) {
  2189. if (!ASN1DEREncOctetString(enc, 0x80000000, ((val)->encryptedContent).length, ((val)->encryptedContent).value))
  2190. return 0;
  2191. }
  2192. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  2193. return 0;
  2194. return 1;
  2195. }
  2196. static int ASN1CALL ASN1Dec_EncryptedContentInfo(ASN1decoding_t dec, ASN1uint32_t tag, EncryptedContentInfo *val)
  2197. {
  2198. ASN1decoding_t dd;
  2199. ASN1octet_t *di;
  2200. ASN1uint32_t t;
  2201. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  2202. return 0;
  2203. ZeroMemory((val)->o, 1);
  2204. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->contentType))
  2205. return 0;
  2206. if (!ASN1Dec_ContentEncryptionAlgId(dd, 0, &(val)->contentEncryptionAlgorithm))
  2207. return 0;
  2208. ASN1BERDecPeekTag(dd, &t);
  2209. if (t == 0x80000000) {
  2210. (val)->o[0] |= 0x80;
  2211. if (!ASN1BERDecOctetString(dd, 0x80000000, &(val)->encryptedContent))
  2212. return 0;
  2213. }
  2214. if (!ASN1BERDecEndOfContents(dec, dd, di))
  2215. return 0;
  2216. return 1;
  2217. }
  2218. static void ASN1CALL ASN1Free_EncryptedContentInfo(EncryptedContentInfo *val)
  2219. {
  2220. if (val) {
  2221. ASN1Free_ContentEncryptionAlgId(&(val)->contentEncryptionAlgorithm);
  2222. if ((val)->o[0] & 0x80) {
  2223. ASN1octetstring_free(&(val)->encryptedContent);
  2224. }
  2225. }
  2226. }
  2227. static int ASN1CALL ASN1Enc_RecipientInfo(ASN1encoding_t enc, ASN1uint32_t tag, RecipientInfo *val)
  2228. {
  2229. ASN1uint32_t nLenOff;
  2230. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  2231. return 0;
  2232. if (!ASN1BEREncS32(enc, 0x2, (val)->version))
  2233. return 0;
  2234. if (!ASN1Enc_IssuerAndSerialNumber(enc, 0, &(val)->issuerAndSerialNumber))
  2235. return 0;
  2236. if (!ASN1Enc_KeyEncryptionAlgId(enc, 0, &(val)->keyEncryptionAlgorithm))
  2237. return 0;
  2238. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->encryptedKey).length, ((val)->encryptedKey).value))
  2239. return 0;
  2240. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  2241. return 0;
  2242. return 1;
  2243. }
  2244. static int ASN1CALL ASN1Dec_RecipientInfo(ASN1decoding_t dec, ASN1uint32_t tag, RecipientInfo *val)
  2245. {
  2246. ASN1decoding_t dd;
  2247. ASN1octet_t *di;
  2248. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  2249. return 0;
  2250. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->version))
  2251. return 0;
  2252. if (!ASN1Dec_IssuerAndSerialNumber(dd, 0, &(val)->issuerAndSerialNumber))
  2253. return 0;
  2254. if (!ASN1Dec_KeyEncryptionAlgId(dd, 0, &(val)->keyEncryptionAlgorithm))
  2255. return 0;
  2256. if (!ASN1BERDecOctetString(dd, 0x4, &(val)->encryptedKey))
  2257. return 0;
  2258. if (!ASN1BERDecEndOfContents(dec, dd, di))
  2259. return 0;
  2260. return 1;
  2261. }
  2262. static void ASN1CALL ASN1Free_RecipientInfo(RecipientInfo *val)
  2263. {
  2264. if (val) {
  2265. ASN1Free_IssuerAndSerialNumber(&(val)->issuerAndSerialNumber);
  2266. ASN1Free_KeyEncryptionAlgId(&(val)->keyEncryptionAlgorithm);
  2267. ASN1octetstring_free(&(val)->encryptedKey);
  2268. }
  2269. }
  2270. static int ASN1CALL ASN1Enc_SignedAndEnvelopedData(ASN1encoding_t enc, ASN1uint32_t tag, SignedAndEnvelopedData *val)
  2271. {
  2272. ASN1uint32_t nLenOff;
  2273. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  2274. return 0;
  2275. if (!ASN1BEREncS32(enc, 0x2, (val)->version))
  2276. return 0;
  2277. if (!ASN1Enc_RecipientInfos(enc, 0, &(val)->recipientInfos))
  2278. return 0;
  2279. if (!ASN1Enc_DigestAlgorithmIdentifiers(enc, 0, &(val)->digestAlgorithms))
  2280. return 0;
  2281. if (!ASN1Enc_EncryptedContentInfo(enc, 0, &(val)->encryptedContentInfo))
  2282. return 0;
  2283. if ((val)->o[0] & 0x80) {
  2284. if (!ASN1Enc_Certificates(enc, 0x80000000, &(val)->certificates))
  2285. return 0;
  2286. }
  2287. if ((val)->o[0] & 0x40) {
  2288. if (!ASN1Enc_Crls(enc, 0x80000001, &(val)->crls))
  2289. return 0;
  2290. }
  2291. if (!ASN1Enc_SignerInfos(enc, 0, &(val)->signerInfos))
  2292. return 0;
  2293. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  2294. return 0;
  2295. return 1;
  2296. }
  2297. static int ASN1CALL ASN1Dec_SignedAndEnvelopedData(ASN1decoding_t dec, ASN1uint32_t tag, SignedAndEnvelopedData *val)
  2298. {
  2299. ASN1decoding_t dd;
  2300. ASN1octet_t *di;
  2301. ASN1uint32_t t;
  2302. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  2303. return 0;
  2304. ZeroMemory((val)->o, 1);
  2305. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->version))
  2306. return 0;
  2307. if (!ASN1Dec_RecipientInfos(dd, 0, &(val)->recipientInfos))
  2308. return 0;
  2309. if (!ASN1Dec_DigestAlgorithmIdentifiers(dd, 0, &(val)->digestAlgorithms))
  2310. return 0;
  2311. if (!ASN1Dec_EncryptedContentInfo(dd, 0, &(val)->encryptedContentInfo))
  2312. return 0;
  2313. ASN1BERDecPeekTag(dd, &t);
  2314. if (t == 0x80000000) {
  2315. (val)->o[0] |= 0x80;
  2316. if (!ASN1Dec_Certificates(dd, 0x80000000, &(val)->certificates))
  2317. return 0;
  2318. }
  2319. ASN1BERDecPeekTag(dd, &t);
  2320. if (t == 0x80000001) {
  2321. (val)->o[0] |= 0x40;
  2322. if (!ASN1Dec_Crls(dd, 0x80000001, &(val)->crls))
  2323. return 0;
  2324. }
  2325. if (!ASN1Dec_SignerInfos(dd, 0, &(val)->signerInfos))
  2326. return 0;
  2327. if (!ASN1BERDecEndOfContents(dec, dd, di))
  2328. return 0;
  2329. return 1;
  2330. }
  2331. static void ASN1CALL ASN1Free_SignedAndEnvelopedData(SignedAndEnvelopedData *val)
  2332. {
  2333. if (val) {
  2334. ASN1Free_RecipientInfos(&(val)->recipientInfos);
  2335. ASN1Free_DigestAlgorithmIdentifiers(&(val)->digestAlgorithms);
  2336. ASN1Free_EncryptedContentInfo(&(val)->encryptedContentInfo);
  2337. if ((val)->o[0] & 0x80) {
  2338. ASN1Free_Certificates(&(val)->certificates);
  2339. }
  2340. if ((val)->o[0] & 0x40) {
  2341. ASN1Free_Crls(&(val)->crls);
  2342. }
  2343. ASN1Free_SignerInfos(&(val)->signerInfos);
  2344. }
  2345. }
  2346. static int ASN1CALL ASN1Enc_DigestedData(ASN1encoding_t enc, ASN1uint32_t tag, DigestedData *val)
  2347. {
  2348. ASN1uint32_t nLenOff;
  2349. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  2350. return 0;
  2351. if (!ASN1BEREncS32(enc, 0x2, (val)->version))
  2352. return 0;
  2353. if (!ASN1Enc_DigestAlgorithmIdentifier(enc, 0, &(val)->digestAlgorithm))
  2354. return 0;
  2355. if (!ASN1Enc_ContentInfo(enc, 0, &(val)->contentInfo))
  2356. return 0;
  2357. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->digest).length, ((val)->digest).value))
  2358. return 0;
  2359. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  2360. return 0;
  2361. return 1;
  2362. }
  2363. static int ASN1CALL ASN1Dec_DigestedData(ASN1decoding_t dec, ASN1uint32_t tag, DigestedData *val)
  2364. {
  2365. ASN1decoding_t dd;
  2366. ASN1octet_t *di;
  2367. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  2368. return 0;
  2369. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->version))
  2370. return 0;
  2371. if (!ASN1Dec_DigestAlgorithmIdentifier(dd, 0, &(val)->digestAlgorithm))
  2372. return 0;
  2373. if (!ASN1Dec_ContentInfo(dd, 0, &(val)->contentInfo))
  2374. return 0;
  2375. if (!ASN1BERDecOctetString(dd, 0x4, &(val)->digest))
  2376. return 0;
  2377. if (!ASN1BERDecEndOfContents(dec, dd, di))
  2378. return 0;
  2379. return 1;
  2380. }
  2381. static void ASN1CALL ASN1Free_DigestedData(DigestedData *val)
  2382. {
  2383. if (val) {
  2384. ASN1Free_DigestAlgorithmIdentifier(&(val)->digestAlgorithm);
  2385. ASN1Free_ContentInfo(&(val)->contentInfo);
  2386. ASN1octetstring_free(&(val)->digest);
  2387. }
  2388. }
  2389. static int ASN1CALL ASN1Enc_EncryptedData(ASN1encoding_t enc, ASN1uint32_t tag, EncryptedData *val)
  2390. {
  2391. ASN1uint32_t nLenOff;
  2392. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  2393. return 0;
  2394. if (!ASN1BEREncS32(enc, 0x2, (val)->version))
  2395. return 0;
  2396. if (!ASN1Enc_EncryptedContentInfo(enc, 0, &(val)->encryptedContentInfo))
  2397. return 0;
  2398. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  2399. return 0;
  2400. return 1;
  2401. }
  2402. static int ASN1CALL ASN1Dec_EncryptedData(ASN1decoding_t dec, ASN1uint32_t tag, EncryptedData *val)
  2403. {
  2404. ASN1decoding_t dd;
  2405. ASN1octet_t *di;
  2406. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  2407. return 0;
  2408. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->version))
  2409. return 0;
  2410. if (!ASN1Dec_EncryptedContentInfo(dd, 0, &(val)->encryptedContentInfo))
  2411. return 0;
  2412. if (!ASN1BERDecEndOfContents(dec, dd, di))
  2413. return 0;
  2414. return 1;
  2415. }
  2416. static void ASN1CALL ASN1Free_EncryptedData(EncryptedData *val)
  2417. {
  2418. if (val) {
  2419. ASN1Free_EncryptedContentInfo(&(val)->encryptedContentInfo);
  2420. }
  2421. }
  2422. static int ASN1CALL ASN1Enc_CertIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, CertIdentifier *val)
  2423. {
  2424. switch ((val)->choice) {
  2425. case 1:
  2426. if (!ASN1Enc_IssuerAndSerialNumber(enc, 0, &(val)->u.issuerAndSerialNumber))
  2427. return 0;
  2428. break;
  2429. case 2:
  2430. if (!ASN1DEREncOctetString(enc, 0x80000000, ((val)->u.subjectKeyIdentifier).length, ((val)->u.subjectKeyIdentifier).value))
  2431. return 0;
  2432. break;
  2433. }
  2434. return 1;
  2435. }
  2436. static int ASN1CALL ASN1Dec_CertIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, CertIdentifier *val)
  2437. {
  2438. ASN1uint32_t t;
  2439. if (!ASN1BERDecPeekTag(dec, &t))
  2440. return 0;
  2441. switch (t) {
  2442. case 0x10:
  2443. (val)->choice = 1;
  2444. if (!ASN1Dec_IssuerAndSerialNumber(dec, 0, &(val)->u.issuerAndSerialNumber))
  2445. return 0;
  2446. break;
  2447. case 0x80000000:
  2448. (val)->choice = 2;
  2449. if (!ASN1BERDecOctetString(dec, 0x80000000, &(val)->u.subjectKeyIdentifier))
  2450. return 0;
  2451. break;
  2452. default:
  2453. ASN1DecSetError(dec, ASN1_ERR_CORRUPT);
  2454. return 0;
  2455. }
  2456. return 1;
  2457. }
  2458. static void ASN1CALL ASN1Free_CertIdentifier(CertIdentifier *val)
  2459. {
  2460. if (val) {
  2461. switch ((val)->choice) {
  2462. case 1:
  2463. ASN1Free_IssuerAndSerialNumber(&(val)->u.issuerAndSerialNumber);
  2464. break;
  2465. case 2:
  2466. ASN1octetstring_free(&(val)->u.subjectKeyIdentifier);
  2467. break;
  2468. }
  2469. }
  2470. }
  2471. static int ASN1CALL ASN1Enc_OriginatorInfo(ASN1encoding_t enc, ASN1uint32_t tag, OriginatorInfo *val)
  2472. {
  2473. ASN1uint32_t nLenOff;
  2474. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  2475. return 0;
  2476. if ((val)->o[0] & 0x80) {
  2477. if (!ASN1Enc_Certificates(enc, 0x80000000, &(val)->certificates))
  2478. return 0;
  2479. }
  2480. if ((val)->o[0] & 0x40) {
  2481. if (!ASN1Enc_Crls(enc, 0x80000001, &(val)->crls))
  2482. return 0;
  2483. }
  2484. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  2485. return 0;
  2486. return 1;
  2487. }
  2488. static int ASN1CALL ASN1Dec_OriginatorInfo(ASN1decoding_t dec, ASN1uint32_t tag, OriginatorInfo *val)
  2489. {
  2490. ASN1decoding_t dd;
  2491. ASN1octet_t *di;
  2492. ASN1uint32_t t;
  2493. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  2494. return 0;
  2495. ZeroMemory((val)->o, 1);
  2496. ASN1BERDecPeekTag(dd, &t);
  2497. if (t == 0x80000000) {
  2498. (val)->o[0] |= 0x80;
  2499. if (!ASN1Dec_Certificates(dd, 0x80000000, &(val)->certificates))
  2500. return 0;
  2501. }
  2502. ASN1BERDecPeekTag(dd, &t);
  2503. if (t == 0x80000001) {
  2504. (val)->o[0] |= 0x40;
  2505. if (!ASN1Dec_Crls(dd, 0x80000001, &(val)->crls))
  2506. return 0;
  2507. }
  2508. if (!ASN1BERDecEndOfContents(dec, dd, di))
  2509. return 0;
  2510. return 1;
  2511. }
  2512. static void ASN1CALL ASN1Free_OriginatorInfo(OriginatorInfo *val)
  2513. {
  2514. if (val) {
  2515. if ((val)->o[0] & 0x80) {
  2516. ASN1Free_Certificates(&(val)->certificates);
  2517. }
  2518. if ((val)->o[0] & 0x40) {
  2519. ASN1Free_Crls(&(val)->crls);
  2520. }
  2521. }
  2522. }
  2523. static int ASN1CALL ASN1Enc_OriginatorInfoNC(ASN1encoding_t enc, ASN1uint32_t tag, OriginatorInfoNC *val)
  2524. {
  2525. ASN1uint32_t nLenOff;
  2526. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  2527. return 0;
  2528. if ((val)->o[0] & 0x80) {
  2529. if (!ASN1Enc_CertificatesNC(enc, 0x80000000, &(val)->certificates))
  2530. return 0;
  2531. }
  2532. if ((val)->o[0] & 0x40) {
  2533. if (!ASN1Enc_CrlsNC(enc, 0x80000001, &(val)->crls))
  2534. return 0;
  2535. }
  2536. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  2537. return 0;
  2538. return 1;
  2539. }
  2540. static int ASN1CALL ASN1Dec_OriginatorInfoNC(ASN1decoding_t dec, ASN1uint32_t tag, OriginatorInfoNC *val)
  2541. {
  2542. ASN1decoding_t dd;
  2543. ASN1octet_t *di;
  2544. ASN1uint32_t t;
  2545. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  2546. return 0;
  2547. ZeroMemory((val)->o, 1);
  2548. ASN1BERDecPeekTag(dd, &t);
  2549. if (t == 0x80000000) {
  2550. (val)->o[0] |= 0x80;
  2551. if (!ASN1Dec_CertificatesNC(dd, 0x80000000, &(val)->certificates))
  2552. return 0;
  2553. }
  2554. ASN1BERDecPeekTag(dd, &t);
  2555. if (t == 0x80000001) {
  2556. (val)->o[0] |= 0x40;
  2557. if (!ASN1Dec_CrlsNC(dd, 0x80000001, &(val)->crls))
  2558. return 0;
  2559. }
  2560. if (!ASN1BERDecEndOfContents(dec, dd, di))
  2561. return 0;
  2562. return 1;
  2563. }
  2564. static void ASN1CALL ASN1Free_OriginatorInfoNC(OriginatorInfoNC *val)
  2565. {
  2566. if (val) {
  2567. if ((val)->o[0] & 0x80) {
  2568. ASN1Free_CertificatesNC(&(val)->certificates);
  2569. }
  2570. if ((val)->o[0] & 0x40) {
  2571. ASN1Free_CrlsNC(&(val)->crls);
  2572. }
  2573. }
  2574. }
  2575. static int ASN1CALL ASN1Enc_CmsRecipientInfos(ASN1encoding_t enc, ASN1uint32_t tag, CmsRecipientInfos *val)
  2576. {
  2577. ASN1uint32_t nLenOff;
  2578. void *pBlk;
  2579. ASN1uint32_t i;
  2580. ASN1encoding_t enc2;
  2581. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  2582. return 0;
  2583. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  2584. return 0;
  2585. for (i = 0; i < (val)->count; i++) {
  2586. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  2587. return 0;
  2588. if (!ASN1Enc_CmsRecipientInfo(enc2, 0, &((val)->value)[i]))
  2589. return 0;
  2590. if (!ASN1DEREncFlushBlkElement(pBlk))
  2591. return 0;
  2592. }
  2593. if (!ASN1DEREncEndBlk(pBlk))
  2594. return 0;
  2595. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  2596. return 0;
  2597. return 1;
  2598. }
  2599. static int ASN1CALL ASN1Dec_CmsRecipientInfos(ASN1decoding_t dec, ASN1uint32_t tag, CmsRecipientInfos *val)
  2600. {
  2601. ASN1decoding_t dd;
  2602. ASN1octet_t *di;
  2603. ASN1uint32_t t;
  2604. ASN1uint32_t n;
  2605. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  2606. return 0;
  2607. (val)->count = n = 0;
  2608. (val)->value = NULL;
  2609. while (ASN1BERDecNotEndOfContents(dd, di)) {
  2610. if (!ASN1BERDecPeekTag(dd, &t))
  2611. return 0;
  2612. if ((val)->count >= n) {
  2613. n = n ? (n << 1) : 16;
  2614. if (!((val)->value = (CmsRecipientInfo *)ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  2615. return 0;
  2616. }
  2617. if (!ASN1Dec_CmsRecipientInfo(dd, 0, &((val)->value)[(val)->count]))
  2618. return 0;
  2619. ((val)->count)++;
  2620. }
  2621. if (!ASN1BERDecEndOfContents(dec, dd, di))
  2622. return 0;
  2623. return 1;
  2624. }
  2625. static void ASN1CALL ASN1Free_CmsRecipientInfos(CmsRecipientInfos *val)
  2626. {
  2627. ASN1uint32_t i;
  2628. if (val) {
  2629. ASN1Free_CmsRecipientInfo(&(val)->value[0]);
  2630. for (i = 1; i < (val)->count; i++) {
  2631. ASN1Free_CmsRecipientInfo(&(val)->value[i]);
  2632. }
  2633. ASN1Free((val)->value);
  2634. }
  2635. }
  2636. static int ASN1CALL ASN1Enc_KeyTransRecipientInfo(ASN1encoding_t enc, ASN1uint32_t tag, KeyTransRecipientInfo *val)
  2637. {
  2638. ASN1uint32_t nLenOff;
  2639. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  2640. return 0;
  2641. if (!ASN1BEREncS32(enc, 0x2, (val)->version))
  2642. return 0;
  2643. if (!ASN1Enc_CertIdentifier(enc, 0, &(val)->rid))
  2644. return 0;
  2645. if (!ASN1Enc_KeyEncryptionAlgId(enc, 0, &(val)->keyEncryptionAlgorithm))
  2646. return 0;
  2647. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->encryptedKey).length, ((val)->encryptedKey).value))
  2648. return 0;
  2649. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  2650. return 0;
  2651. return 1;
  2652. }
  2653. static int ASN1CALL ASN1Dec_KeyTransRecipientInfo(ASN1decoding_t dec, ASN1uint32_t tag, KeyTransRecipientInfo *val)
  2654. {
  2655. ASN1decoding_t dd;
  2656. ASN1octet_t *di;
  2657. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  2658. return 0;
  2659. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->version))
  2660. return 0;
  2661. if (!ASN1Dec_CertIdentifier(dd, 0, &(val)->rid))
  2662. return 0;
  2663. if (!ASN1Dec_KeyEncryptionAlgId(dd, 0, &(val)->keyEncryptionAlgorithm))
  2664. return 0;
  2665. if (!ASN1BERDecOctetString(dd, 0x4, &(val)->encryptedKey))
  2666. return 0;
  2667. if (!ASN1BERDecEndOfContents(dec, dd, di))
  2668. return 0;
  2669. return 1;
  2670. }
  2671. static void ASN1CALL ASN1Free_KeyTransRecipientInfo(KeyTransRecipientInfo *val)
  2672. {
  2673. if (val) {
  2674. ASN1Free_CertIdentifier(&(val)->rid);
  2675. ASN1Free_KeyEncryptionAlgId(&(val)->keyEncryptionAlgorithm);
  2676. ASN1octetstring_free(&(val)->encryptedKey);
  2677. }
  2678. }
  2679. static int ASN1CALL ASN1Enc_OriginatorPublicKey(ASN1encoding_t enc, ASN1uint32_t tag, OriginatorPublicKey *val)
  2680. {
  2681. ASN1uint32_t nLenOff;
  2682. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  2683. return 0;
  2684. if (!ASN1Enc_AlgorithmIdentifier(enc, 0, &(val)->algorithm))
  2685. return 0;
  2686. if (!ASN1DEREncBitString(enc, 0x3, ((val)->publicKey).length, ((val)->publicKey).value))
  2687. return 0;
  2688. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  2689. return 0;
  2690. return 1;
  2691. }
  2692. static int ASN1CALL ASN1Dec_OriginatorPublicKey(ASN1decoding_t dec, ASN1uint32_t tag, OriginatorPublicKey *val)
  2693. {
  2694. ASN1decoding_t dd;
  2695. ASN1octet_t *di;
  2696. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  2697. return 0;
  2698. if (!ASN1Dec_AlgorithmIdentifier(dd, 0, &(val)->algorithm))
  2699. return 0;
  2700. if (!ASN1BERDecBitString(dd, 0x3, &(val)->publicKey))
  2701. return 0;
  2702. if (!ASN1BERDecEndOfContents(dec, dd, di))
  2703. return 0;
  2704. return 1;
  2705. }
  2706. static void ASN1CALL ASN1Free_OriginatorPublicKey(OriginatorPublicKey *val)
  2707. {
  2708. if (val) {
  2709. ASN1Free_AlgorithmIdentifier(&(val)->algorithm);
  2710. ASN1bitstring_free(&(val)->publicKey);
  2711. }
  2712. }
  2713. static int ASN1CALL ASN1Enc_RecipientEncryptedKeys(ASN1encoding_t enc, ASN1uint32_t tag, RecipientEncryptedKeys *val)
  2714. {
  2715. ASN1uint32_t nLenOff;
  2716. ASN1uint32_t i;
  2717. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  2718. return 0;
  2719. for (i = 0; i < (val)->count; i++) {
  2720. if (!ASN1Enc_RecipientEncryptedKey(enc, 0, &((val)->value)[i]))
  2721. return 0;
  2722. }
  2723. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  2724. return 0;
  2725. return 1;
  2726. }
  2727. static int ASN1CALL ASN1Dec_RecipientEncryptedKeys(ASN1decoding_t dec, ASN1uint32_t tag, RecipientEncryptedKeys *val)
  2728. {
  2729. ASN1decoding_t dd;
  2730. ASN1octet_t *di;
  2731. ASN1uint32_t t;
  2732. ASN1uint32_t n;
  2733. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  2734. return 0;
  2735. (val)->count = n = 0;
  2736. (val)->value = NULL;
  2737. while (ASN1BERDecNotEndOfContents(dd, di)) {
  2738. if (!ASN1BERDecPeekTag(dd, &t))
  2739. return 0;
  2740. if ((val)->count >= n) {
  2741. n = n ? (n << 1) : 16;
  2742. if (!((val)->value = (RecipientEncryptedKey *)ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  2743. return 0;
  2744. }
  2745. if (!ASN1Dec_RecipientEncryptedKey(dd, 0, &((val)->value)[(val)->count]))
  2746. return 0;
  2747. ((val)->count)++;
  2748. }
  2749. if (!ASN1BERDecEndOfContents(dec, dd, di))
  2750. return 0;
  2751. return 1;
  2752. }
  2753. static void ASN1CALL ASN1Free_RecipientEncryptedKeys(RecipientEncryptedKeys *val)
  2754. {
  2755. ASN1uint32_t i;
  2756. if (val) {
  2757. ASN1Free_RecipientEncryptedKey(&(val)->value[0]);
  2758. for (i = 1; i < (val)->count; i++) {
  2759. ASN1Free_RecipientEncryptedKey(&(val)->value[i]);
  2760. }
  2761. ASN1Free((val)->value);
  2762. }
  2763. }
  2764. static int ASN1CALL ASN1Enc_OtherKeyAttribute(ASN1encoding_t enc, ASN1uint32_t tag, OtherKeyAttribute *val)
  2765. {
  2766. ASN1uint32_t nLenOff;
  2767. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  2768. return 0;
  2769. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->keyAttrId))
  2770. return 0;
  2771. if ((val)->o[0] & 0x80) {
  2772. if (!ASN1BEREncOpenType(enc, &(val)->keyAttr))
  2773. return 0;
  2774. }
  2775. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  2776. return 0;
  2777. return 1;
  2778. }
  2779. static int ASN1CALL ASN1Dec_OtherKeyAttribute(ASN1decoding_t dec, ASN1uint32_t tag, OtherKeyAttribute *val)
  2780. {
  2781. ASN1decoding_t dd;
  2782. ASN1octet_t *di;
  2783. ASN1uint32_t t;
  2784. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  2785. return 0;
  2786. ZeroMemory((val)->o, 1);
  2787. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->keyAttrId))
  2788. return 0;
  2789. if (ASN1BERDecPeekTag(dd, &t)) {
  2790. (val)->o[0] |= 0x80;
  2791. if (!ASN1BERDecOpenType(dd, &(val)->keyAttr))
  2792. return 0;
  2793. }
  2794. if (!ASN1BERDecEndOfContents(dec, dd, di))
  2795. return 0;
  2796. return 1;
  2797. }
  2798. static void ASN1CALL ASN1Free_OtherKeyAttribute(OtherKeyAttribute *val)
  2799. {
  2800. if (val) {
  2801. if ((val)->o[0] & 0x80) {
  2802. ASN1open_free(&(val)->keyAttr);
  2803. }
  2804. }
  2805. }
  2806. static int ASN1CALL ASN1Enc_MailListKeyIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, MailListKeyIdentifier *val)
  2807. {
  2808. ASN1uint32_t nLenOff;
  2809. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  2810. return 0;
  2811. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->kekIdentifier).length, ((val)->kekIdentifier).value))
  2812. return 0;
  2813. if ((val)->o[0] & 0x80) {
  2814. if (!ASN1DEREncGeneralizedTime(enc, 0x18, &(val)->date))
  2815. return 0;
  2816. }
  2817. if ((val)->o[0] & 0x40) {
  2818. if (!ASN1Enc_OtherKeyAttribute(enc, 0, &(val)->other))
  2819. return 0;
  2820. }
  2821. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  2822. return 0;
  2823. return 1;
  2824. }
  2825. static int ASN1CALL ASN1Dec_MailListKeyIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, MailListKeyIdentifier *val)
  2826. {
  2827. ASN1decoding_t dd;
  2828. ASN1octet_t *di;
  2829. ASN1uint32_t t;
  2830. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  2831. return 0;
  2832. ZeroMemory((val)->o, 1);
  2833. if (!ASN1BERDecOctetString(dd, 0x4, &(val)->kekIdentifier))
  2834. return 0;
  2835. ASN1BERDecPeekTag(dd, &t);
  2836. if (t == 0x18) {
  2837. (val)->o[0] |= 0x80;
  2838. if (!ASN1BERDecGeneralizedTime(dd, 0x18, &(val)->date))
  2839. return 0;
  2840. }
  2841. ASN1BERDecPeekTag(dd, &t);
  2842. if (t == 0x10) {
  2843. (val)->o[0] |= 0x40;
  2844. if (!ASN1Dec_OtherKeyAttribute(dd, 0, &(val)->other))
  2845. return 0;
  2846. }
  2847. if (!ASN1BERDecEndOfContents(dec, dd, di))
  2848. return 0;
  2849. return 1;
  2850. }
  2851. static void ASN1CALL ASN1Free_MailListKeyIdentifier(MailListKeyIdentifier *val)
  2852. {
  2853. if (val) {
  2854. ASN1octetstring_free(&(val)->kekIdentifier);
  2855. if ((val)->o[0] & 0x80) {
  2856. }
  2857. if ((val)->o[0] & 0x40) {
  2858. ASN1Free_OtherKeyAttribute(&(val)->other);
  2859. }
  2860. }
  2861. }
  2862. static int ASN1CALL ASN1Enc_DigestInfo(ASN1encoding_t enc, ASN1uint32_t tag, DigestInfo *val)
  2863. {
  2864. ASN1uint32_t nLenOff;
  2865. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  2866. return 0;
  2867. if (!ASN1Enc_DigestAlgorithmIdentifier(enc, 0, &(val)->digestAlgorithm))
  2868. return 0;
  2869. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->digest).length, ((val)->digest).value))
  2870. return 0;
  2871. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  2872. return 0;
  2873. return 1;
  2874. }
  2875. static int ASN1CALL ASN1Dec_DigestInfo(ASN1decoding_t dec, ASN1uint32_t tag, DigestInfo *val)
  2876. {
  2877. ASN1decoding_t dd;
  2878. ASN1octet_t *di;
  2879. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  2880. return 0;
  2881. if (!ASN1Dec_DigestAlgorithmIdentifier(dd, 0, &(val)->digestAlgorithm))
  2882. return 0;
  2883. if (!ASN1BERDecOctetString(dd, 0x4, &(val)->digest))
  2884. return 0;
  2885. if (!ASN1BERDecEndOfContents(dec, dd, di))
  2886. return 0;
  2887. return 1;
  2888. }
  2889. static void ASN1CALL ASN1Free_DigestInfo(DigestInfo *val)
  2890. {
  2891. if (val) {
  2892. ASN1Free_DigestAlgorithmIdentifier(&(val)->digestAlgorithm);
  2893. ASN1octetstring_free(&(val)->digest);
  2894. }
  2895. }
  2896. static int ASN1CALL ASN1Enc_SignedData(ASN1encoding_t enc, ASN1uint32_t tag, SignedData *val)
  2897. {
  2898. ASN1uint32_t nLenOff;
  2899. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  2900. return 0;
  2901. if (!ASN1BEREncS32(enc, 0x2, (val)->version))
  2902. return 0;
  2903. if (!ASN1Enc_DigestAlgorithmIdentifiers(enc, 0, &(val)->digestAlgorithms))
  2904. return 0;
  2905. if (!ASN1Enc_ContentInfo(enc, 0, &(val)->contentInfo))
  2906. return 0;
  2907. if ((val)->o[0] & 0x80) {
  2908. if (!ASN1Enc_Certificates(enc, 0x80000000, &(val)->certificates))
  2909. return 0;
  2910. }
  2911. if ((val)->o[0] & 0x40) {
  2912. if (!ASN1Enc_Crls(enc, 0x80000001, &(val)->crls))
  2913. return 0;
  2914. }
  2915. if (!ASN1Enc_SignerInfos(enc, 0, &(val)->signerInfos))
  2916. return 0;
  2917. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  2918. return 0;
  2919. return 1;
  2920. }
  2921. static int ASN1CALL ASN1Dec_SignedData(ASN1decoding_t dec, ASN1uint32_t tag, SignedData *val)
  2922. {
  2923. ASN1decoding_t dd;
  2924. ASN1octet_t *di;
  2925. ASN1uint32_t t;
  2926. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  2927. return 0;
  2928. ZeroMemory((val)->o, 1);
  2929. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->version))
  2930. return 0;
  2931. if (!ASN1Dec_DigestAlgorithmIdentifiers(dd, 0, &(val)->digestAlgorithms))
  2932. return 0;
  2933. if (!ASN1Dec_ContentInfo(dd, 0, &(val)->contentInfo))
  2934. return 0;
  2935. ASN1BERDecPeekTag(dd, &t);
  2936. if (t == 0x80000000) {
  2937. (val)->o[0] |= 0x80;
  2938. if (!ASN1Dec_Certificates(dd, 0x80000000, &(val)->certificates))
  2939. return 0;
  2940. }
  2941. ASN1BERDecPeekTag(dd, &t);
  2942. if (t == 0x80000001) {
  2943. (val)->o[0] |= 0x40;
  2944. if (!ASN1Dec_Crls(dd, 0x80000001, &(val)->crls))
  2945. return 0;
  2946. }
  2947. if (!ASN1Dec_SignerInfos(dd, 0, &(val)->signerInfos))
  2948. return 0;
  2949. if (!ASN1BERDecEndOfContents(dec, dd, di))
  2950. return 0;
  2951. return 1;
  2952. }
  2953. static void ASN1CALL ASN1Free_SignedData(SignedData *val)
  2954. {
  2955. if (val) {
  2956. ASN1Free_DigestAlgorithmIdentifiers(&(val)->digestAlgorithms);
  2957. ASN1Free_ContentInfo(&(val)->contentInfo);
  2958. if ((val)->o[0] & 0x80) {
  2959. ASN1Free_Certificates(&(val)->certificates);
  2960. }
  2961. if ((val)->o[0] & 0x40) {
  2962. ASN1Free_Crls(&(val)->crls);
  2963. }
  2964. ASN1Free_SignerInfos(&(val)->signerInfos);
  2965. }
  2966. }
  2967. static int ASN1CALL ASN1Enc_SignerInfo(ASN1encoding_t enc, ASN1uint32_t tag, SignerInfo *val)
  2968. {
  2969. ASN1uint32_t nLenOff;
  2970. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  2971. return 0;
  2972. if (!ASN1BEREncS32(enc, 0x2, (val)->version))
  2973. return 0;
  2974. if (!ASN1Enc_CertIdentifier(enc, 0, &(val)->sid))
  2975. return 0;
  2976. if (!ASN1Enc_DigestAlgorithmIdentifier(enc, 0, &(val)->digestAlgorithm))
  2977. return 0;
  2978. if ((val)->o[0] & 0x80) {
  2979. if (!ASN1Enc_Attributes(enc, 0x80000000, &(val)->authenticatedAttributes))
  2980. return 0;
  2981. }
  2982. if (!ASN1Enc_DigestEncryptionAlgId(enc, 0, &(val)->digestEncryptionAlgorithm))
  2983. return 0;
  2984. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->encryptedDigest).length, ((val)->encryptedDigest).value))
  2985. return 0;
  2986. if ((val)->o[0] & 0x40) {
  2987. if (!ASN1Enc_Attributes(enc, 0x80000001, &(val)->unauthAttributes))
  2988. return 0;
  2989. }
  2990. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  2991. return 0;
  2992. return 1;
  2993. }
  2994. static int ASN1CALL ASN1Dec_SignerInfo(ASN1decoding_t dec, ASN1uint32_t tag, SignerInfo *val)
  2995. {
  2996. ASN1decoding_t dd;
  2997. ASN1octet_t *di;
  2998. ASN1uint32_t t;
  2999. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  3000. return 0;
  3001. ZeroMemory((val)->o, 1);
  3002. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->version))
  3003. return 0;
  3004. if (!ASN1Dec_CertIdentifier(dd, 0, &(val)->sid))
  3005. return 0;
  3006. if (!ASN1Dec_DigestAlgorithmIdentifier(dd, 0, &(val)->digestAlgorithm))
  3007. return 0;
  3008. ASN1BERDecPeekTag(dd, &t);
  3009. if (t == 0x80000000) {
  3010. (val)->o[0] |= 0x80;
  3011. if (!ASN1Dec_Attributes(dd, 0x80000000, &(val)->authenticatedAttributes))
  3012. return 0;
  3013. }
  3014. if (!ASN1Dec_DigestEncryptionAlgId(dd, 0, &(val)->digestEncryptionAlgorithm))
  3015. return 0;
  3016. if (!ASN1BERDecOctetString(dd, 0x4, &(val)->encryptedDigest))
  3017. return 0;
  3018. ASN1BERDecPeekTag(dd, &t);
  3019. if (t == 0x80000001) {
  3020. (val)->o[0] |= 0x40;
  3021. if (!ASN1Dec_Attributes(dd, 0x80000001, &(val)->unauthAttributes))
  3022. return 0;
  3023. }
  3024. if (!ASN1BERDecEndOfContents(dec, dd, di))
  3025. return 0;
  3026. return 1;
  3027. }
  3028. static void ASN1CALL ASN1Free_SignerInfo(SignerInfo *val)
  3029. {
  3030. if (val) {
  3031. ASN1Free_CertIdentifier(&(val)->sid);
  3032. ASN1Free_DigestAlgorithmIdentifier(&(val)->digestAlgorithm);
  3033. if ((val)->o[0] & 0x80) {
  3034. ASN1Free_Attributes(&(val)->authenticatedAttributes);
  3035. }
  3036. ASN1Free_DigestEncryptionAlgId(&(val)->digestEncryptionAlgorithm);
  3037. ASN1octetstring_free(&(val)->encryptedDigest);
  3038. if ((val)->o[0] & 0x40) {
  3039. ASN1Free_Attributes(&(val)->unauthAttributes);
  3040. }
  3041. }
  3042. }
  3043. static int ASN1CALL ASN1Enc_SignedDataWithBlobs(ASN1encoding_t enc, ASN1uint32_t tag, SignedDataWithBlobs *val)
  3044. {
  3045. ASN1uint32_t nLenOff;
  3046. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  3047. return 0;
  3048. if (!ASN1BEREncS32(enc, 0x2, (val)->version))
  3049. return 0;
  3050. if (!ASN1Enc_DigestAlgorithmIdentifiersNC(enc, 0, &(val)->digestAlgorithms))
  3051. return 0;
  3052. if (!ASN1Enc_ContentInfoNC(enc, 0, &(val)->contentInfo))
  3053. return 0;
  3054. if ((val)->o[0] & 0x80) {
  3055. if (!ASN1Enc_CertificatesNC(enc, 0x80000000, &(val)->certificates))
  3056. return 0;
  3057. }
  3058. if ((val)->o[0] & 0x40) {
  3059. if (!ASN1Enc_CrlsNC(enc, 0x80000001, &(val)->crls))
  3060. return 0;
  3061. }
  3062. if (!ASN1Enc_SignerInfosNC(enc, 0, &(val)->signerInfos))
  3063. return 0;
  3064. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  3065. return 0;
  3066. return 1;
  3067. }
  3068. static int ASN1CALL ASN1Dec_SignedDataWithBlobs(ASN1decoding_t dec, ASN1uint32_t tag, SignedDataWithBlobs *val)
  3069. {
  3070. ASN1decoding_t dd;
  3071. ASN1octet_t *di;
  3072. ASN1uint32_t t;
  3073. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  3074. return 0;
  3075. ZeroMemory((val)->o, 1);
  3076. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->version))
  3077. return 0;
  3078. if (!ASN1Dec_DigestAlgorithmIdentifiersNC(dd, 0, &(val)->digestAlgorithms))
  3079. return 0;
  3080. if (!ASN1Dec_ContentInfoNC(dd, 0, &(val)->contentInfo))
  3081. return 0;
  3082. ASN1BERDecPeekTag(dd, &t);
  3083. if (t == 0x80000000) {
  3084. (val)->o[0] |= 0x80;
  3085. if (!ASN1Dec_CertificatesNC(dd, 0x80000000, &(val)->certificates))
  3086. return 0;
  3087. }
  3088. ASN1BERDecPeekTag(dd, &t);
  3089. if (t == 0x80000001) {
  3090. (val)->o[0] |= 0x40;
  3091. if (!ASN1Dec_CrlsNC(dd, 0x80000001, &(val)->crls))
  3092. return 0;
  3093. }
  3094. if (!ASN1Dec_SignerInfosNC(dd, 0, &(val)->signerInfos))
  3095. return 0;
  3096. if (!ASN1BERDecEndOfContents(dec, dd, di))
  3097. return 0;
  3098. return 1;
  3099. }
  3100. static void ASN1CALL ASN1Free_SignedDataWithBlobs(SignedDataWithBlobs *val)
  3101. {
  3102. if (val) {
  3103. ASN1Free_DigestAlgorithmIdentifiersNC(&(val)->digestAlgorithms);
  3104. ASN1Free_ContentInfoNC(&(val)->contentInfo);
  3105. if ((val)->o[0] & 0x80) {
  3106. ASN1Free_CertificatesNC(&(val)->certificates);
  3107. }
  3108. if ((val)->o[0] & 0x40) {
  3109. ASN1Free_CrlsNC(&(val)->crls);
  3110. }
  3111. ASN1Free_SignerInfosNC(&(val)->signerInfos);
  3112. }
  3113. }
  3114. static int ASN1CALL ASN1Enc_EnvelopedData(ASN1encoding_t enc, ASN1uint32_t tag, EnvelopedData *val)
  3115. {
  3116. ASN1uint32_t nLenOff;
  3117. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  3118. return 0;
  3119. if (!ASN1BEREncS32(enc, 0x2, (val)->version))
  3120. return 0;
  3121. if (!ASN1Enc_RecipientInfos(enc, 0, &(val)->recipientInfos))
  3122. return 0;
  3123. if (!ASN1Enc_EncryptedContentInfo(enc, 0, &(val)->encryptedContentInfo))
  3124. return 0;
  3125. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  3126. return 0;
  3127. return 1;
  3128. }
  3129. static int ASN1CALL ASN1Dec_EnvelopedData(ASN1decoding_t dec, ASN1uint32_t tag, EnvelopedData *val)
  3130. {
  3131. ASN1decoding_t dd;
  3132. ASN1octet_t *di;
  3133. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  3134. return 0;
  3135. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->version))
  3136. return 0;
  3137. if (!ASN1Dec_RecipientInfos(dd, 0, &(val)->recipientInfos))
  3138. return 0;
  3139. if (!ASN1Dec_EncryptedContentInfo(dd, 0, &(val)->encryptedContentInfo))
  3140. return 0;
  3141. if (!ASN1BERDecEndOfContents(dec, dd, di))
  3142. return 0;
  3143. return 1;
  3144. }
  3145. static void ASN1CALL ASN1Free_EnvelopedData(EnvelopedData *val)
  3146. {
  3147. if (val) {
  3148. ASN1Free_RecipientInfos(&(val)->recipientInfos);
  3149. ASN1Free_EncryptedContentInfo(&(val)->encryptedContentInfo);
  3150. }
  3151. }
  3152. static int ASN1CALL ASN1Enc_CmsEnvelopedData(ASN1encoding_t enc, ASN1uint32_t tag, CmsEnvelopedData *val)
  3153. {
  3154. ASN1uint32_t nLenOff;
  3155. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  3156. return 0;
  3157. if (!ASN1BEREncS32(enc, 0x2, (val)->version))
  3158. return 0;
  3159. if ((val)->o[0] & 0x80) {
  3160. if (!ASN1Enc_OriginatorInfo(enc, 0x80000000, &(val)->originatorInfo))
  3161. return 0;
  3162. }
  3163. if (!ASN1Enc_CmsRecipientInfos(enc, 0, &(val)->recipientInfos))
  3164. return 0;
  3165. if (!ASN1Enc_EncryptedContentInfo(enc, 0, &(val)->encryptedContentInfo))
  3166. return 0;
  3167. if ((val)->o[0] & 0x40) {
  3168. if (!ASN1Enc_Attributes(enc, 0x80000001, &(val)->unprotectedAttrs))
  3169. return 0;
  3170. }
  3171. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  3172. return 0;
  3173. return 1;
  3174. }
  3175. static int ASN1CALL ASN1Dec_CmsEnvelopedData(ASN1decoding_t dec, ASN1uint32_t tag, CmsEnvelopedData *val)
  3176. {
  3177. ASN1decoding_t dd;
  3178. ASN1octet_t *di;
  3179. ASN1uint32_t t;
  3180. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  3181. return 0;
  3182. ZeroMemory((val)->o, 1);
  3183. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->version))
  3184. return 0;
  3185. ASN1BERDecPeekTag(dd, &t);
  3186. if (t == 0x80000000) {
  3187. (val)->o[0] |= 0x80;
  3188. if (!ASN1Dec_OriginatorInfo(dd, 0x80000000, &(val)->originatorInfo))
  3189. return 0;
  3190. }
  3191. if (!ASN1Dec_CmsRecipientInfos(dd, 0, &(val)->recipientInfos))
  3192. return 0;
  3193. if (!ASN1Dec_EncryptedContentInfo(dd, 0, &(val)->encryptedContentInfo))
  3194. return 0;
  3195. ASN1BERDecPeekTag(dd, &t);
  3196. if (t == 0x80000001) {
  3197. (val)->o[0] |= 0x40;
  3198. if (!ASN1Dec_Attributes(dd, 0x80000001, &(val)->unprotectedAttrs))
  3199. return 0;
  3200. }
  3201. if (!ASN1BERDecEndOfContents(dec, dd, di))
  3202. return 0;
  3203. return 1;
  3204. }
  3205. static void ASN1CALL ASN1Free_CmsEnvelopedData(CmsEnvelopedData *val)
  3206. {
  3207. if (val) {
  3208. if ((val)->o[0] & 0x80) {
  3209. ASN1Free_OriginatorInfo(&(val)->originatorInfo);
  3210. }
  3211. ASN1Free_CmsRecipientInfos(&(val)->recipientInfos);
  3212. ASN1Free_EncryptedContentInfo(&(val)->encryptedContentInfo);
  3213. if ((val)->o[0] & 0x40) {
  3214. ASN1Free_Attributes(&(val)->unprotectedAttrs);
  3215. }
  3216. }
  3217. }
  3218. static int ASN1CALL ASN1Enc_OriginatorIdentifierOrKey(ASN1encoding_t enc, ASN1uint32_t tag, OriginatorIdentifierOrKey *val)
  3219. {
  3220. switch ((val)->choice) {
  3221. case 1:
  3222. if (!ASN1Enc_IssuerAndSerialNumber(enc, 0, &(val)->u.issuerAndSerialNumber))
  3223. return 0;
  3224. break;
  3225. case 2:
  3226. if (!ASN1DEREncOctetString(enc, 0x80000000, ((val)->u.subjectKeyIdentifier).length, ((val)->u.subjectKeyIdentifier).value))
  3227. return 0;
  3228. break;
  3229. case 3:
  3230. if (!ASN1Enc_OriginatorPublicKey(enc, 0x80000001, &(val)->u.originatorKey))
  3231. return 0;
  3232. break;
  3233. }
  3234. return 1;
  3235. }
  3236. static int ASN1CALL ASN1Dec_OriginatorIdentifierOrKey(ASN1decoding_t dec, ASN1uint32_t tag, OriginatorIdentifierOrKey *val)
  3237. {
  3238. ASN1uint32_t t;
  3239. if (!ASN1BERDecPeekTag(dec, &t))
  3240. return 0;
  3241. switch (t) {
  3242. case 0x10:
  3243. (val)->choice = 1;
  3244. if (!ASN1Dec_IssuerAndSerialNumber(dec, 0, &(val)->u.issuerAndSerialNumber))
  3245. return 0;
  3246. break;
  3247. case 0x80000000:
  3248. (val)->choice = 2;
  3249. if (!ASN1BERDecOctetString(dec, 0x80000000, &(val)->u.subjectKeyIdentifier))
  3250. return 0;
  3251. break;
  3252. case 0x80000001:
  3253. (val)->choice = 3;
  3254. if (!ASN1Dec_OriginatorPublicKey(dec, 0x80000001, &(val)->u.originatorKey))
  3255. return 0;
  3256. break;
  3257. default:
  3258. ASN1DecSetError(dec, ASN1_ERR_CORRUPT);
  3259. return 0;
  3260. }
  3261. return 1;
  3262. }
  3263. static void ASN1CALL ASN1Free_OriginatorIdentifierOrKey(OriginatorIdentifierOrKey *val)
  3264. {
  3265. if (val) {
  3266. switch ((val)->choice) {
  3267. case 1:
  3268. ASN1Free_IssuerAndSerialNumber(&(val)->u.issuerAndSerialNumber);
  3269. break;
  3270. case 2:
  3271. ASN1octetstring_free(&(val)->u.subjectKeyIdentifier);
  3272. break;
  3273. case 3:
  3274. ASN1Free_OriginatorPublicKey(&(val)->u.originatorKey);
  3275. break;
  3276. }
  3277. }
  3278. }
  3279. static int ASN1CALL ASN1Enc_RecipientKeyIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, RecipientKeyIdentifier *val)
  3280. {
  3281. ASN1uint32_t nLenOff;
  3282. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  3283. return 0;
  3284. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->subjectKeyIdentifier).length, ((val)->subjectKeyIdentifier).value))
  3285. return 0;
  3286. if ((val)->o[0] & 0x80) {
  3287. if (!ASN1DEREncGeneralizedTime(enc, 0x18, &(val)->date))
  3288. return 0;
  3289. }
  3290. if ((val)->o[0] & 0x40) {
  3291. if (!ASN1Enc_OtherKeyAttribute(enc, 0, &(val)->other))
  3292. return 0;
  3293. }
  3294. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  3295. return 0;
  3296. return 1;
  3297. }
  3298. static int ASN1CALL ASN1Dec_RecipientKeyIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, RecipientKeyIdentifier *val)
  3299. {
  3300. ASN1decoding_t dd;
  3301. ASN1octet_t *di;
  3302. ASN1uint32_t t;
  3303. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  3304. return 0;
  3305. ZeroMemory((val)->o, 1);
  3306. if (!ASN1BERDecOctetString(dd, 0x4, &(val)->subjectKeyIdentifier))
  3307. return 0;
  3308. ASN1BERDecPeekTag(dd, &t);
  3309. if (t == 0x18) {
  3310. (val)->o[0] |= 0x80;
  3311. if (!ASN1BERDecGeneralizedTime(dd, 0x18, &(val)->date))
  3312. return 0;
  3313. }
  3314. ASN1BERDecPeekTag(dd, &t);
  3315. if (t == 0x10) {
  3316. (val)->o[0] |= 0x40;
  3317. if (!ASN1Dec_OtherKeyAttribute(dd, 0, &(val)->other))
  3318. return 0;
  3319. }
  3320. if (!ASN1BERDecEndOfContents(dec, dd, di))
  3321. return 0;
  3322. return 1;
  3323. }
  3324. static void ASN1CALL ASN1Free_RecipientKeyIdentifier(RecipientKeyIdentifier *val)
  3325. {
  3326. if (val) {
  3327. ASN1octetstring_free(&(val)->subjectKeyIdentifier);
  3328. if ((val)->o[0] & 0x80) {
  3329. }
  3330. if ((val)->o[0] & 0x40) {
  3331. ASN1Free_OtherKeyAttribute(&(val)->other);
  3332. }
  3333. }
  3334. }
  3335. static int ASN1CALL ASN1Enc_MailListRecipientInfo(ASN1encoding_t enc, ASN1uint32_t tag, MailListRecipientInfo *val)
  3336. {
  3337. ASN1uint32_t nLenOff;
  3338. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  3339. return 0;
  3340. if (!ASN1BEREncS32(enc, 0x2, (val)->version))
  3341. return 0;
  3342. if (!ASN1Enc_MailListKeyIdentifier(enc, 0, &(val)->mlid))
  3343. return 0;
  3344. if (!ASN1Enc_KeyEncryptionAlgId(enc, 0, &(val)->keyEncryptionAlgorithm))
  3345. return 0;
  3346. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->encryptedKey).length, ((val)->encryptedKey).value))
  3347. return 0;
  3348. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  3349. return 0;
  3350. return 1;
  3351. }
  3352. static int ASN1CALL ASN1Dec_MailListRecipientInfo(ASN1decoding_t dec, ASN1uint32_t tag, MailListRecipientInfo *val)
  3353. {
  3354. ASN1decoding_t dd;
  3355. ASN1octet_t *di;
  3356. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  3357. return 0;
  3358. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->version))
  3359. return 0;
  3360. if (!ASN1Dec_MailListKeyIdentifier(dd, 0, &(val)->mlid))
  3361. return 0;
  3362. if (!ASN1Dec_KeyEncryptionAlgId(dd, 0, &(val)->keyEncryptionAlgorithm))
  3363. return 0;
  3364. if (!ASN1BERDecOctetString(dd, 0x4, &(val)->encryptedKey))
  3365. return 0;
  3366. if (!ASN1BERDecEndOfContents(dec, dd, di))
  3367. return 0;
  3368. return 1;
  3369. }
  3370. static void ASN1CALL ASN1Free_MailListRecipientInfo(MailListRecipientInfo *val)
  3371. {
  3372. if (val) {
  3373. ASN1Free_MailListKeyIdentifier(&(val)->mlid);
  3374. ASN1Free_KeyEncryptionAlgId(&(val)->keyEncryptionAlgorithm);
  3375. ASN1octetstring_free(&(val)->encryptedKey);
  3376. }
  3377. }
  3378. static int ASN1CALL ASN1Enc_KeyAgreeRecipientInfo(ASN1encoding_t enc, ASN1uint32_t tag, KeyAgreeRecipientInfo *val)
  3379. {
  3380. ASN1uint32_t nLenOff;
  3381. ASN1uint32_t nLenOff0;
  3382. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  3383. return 0;
  3384. if (!ASN1BEREncS32(enc, 0x2, (val)->version))
  3385. return 0;
  3386. if (!ASN1BEREncExplicitTag(enc, 0x80000000, &nLenOff0))
  3387. return 0;
  3388. if (!ASN1Enc_OriginatorIdentifierOrKey(enc, 0, &(val)->originator))
  3389. return 0;
  3390. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  3391. return 0;
  3392. if ((val)->o[0] & 0x80) {
  3393. if (!ASN1BEREncExplicitTag(enc, 0x80000001, &nLenOff0))
  3394. return 0;
  3395. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->ukm).length, ((val)->ukm).value))
  3396. return 0;
  3397. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  3398. return 0;
  3399. }
  3400. if (!ASN1Enc_KeyEncryptionAlgId(enc, 0, &(val)->keyEncryptionAlgorithm))
  3401. return 0;
  3402. if (!ASN1Enc_RecipientEncryptedKeys(enc, 0, &(val)->recipientEncryptedKeys))
  3403. return 0;
  3404. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  3405. return 0;
  3406. return 1;
  3407. }
  3408. static int ASN1CALL ASN1Dec_KeyAgreeRecipientInfo(ASN1decoding_t dec, ASN1uint32_t tag, KeyAgreeRecipientInfo *val)
  3409. {
  3410. ASN1decoding_t dd;
  3411. ASN1octet_t *di;
  3412. ASN1decoding_t dd0;
  3413. ASN1octet_t *di0;
  3414. ASN1uint32_t t;
  3415. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  3416. return 0;
  3417. ZeroMemory((val)->o, 1);
  3418. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->version))
  3419. return 0;
  3420. if (!ASN1BERDecExplicitTag(dd, 0x80000000, &dd0, &di0))
  3421. return 0;
  3422. if (!ASN1Dec_OriginatorIdentifierOrKey(dd0, 0, &(val)->originator))
  3423. return 0;
  3424. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  3425. return 0;
  3426. ASN1BERDecPeekTag(dd, &t);
  3427. if (t == 0x80000001) {
  3428. (val)->o[0] |= 0x80;
  3429. if (!ASN1BERDecExplicitTag(dd, 0x80000001, &dd0, &di0))
  3430. return 0;
  3431. if (!ASN1BERDecOctetString(dd0, 0x4, &(val)->ukm))
  3432. return 0;
  3433. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  3434. return 0;
  3435. }
  3436. if (!ASN1Dec_KeyEncryptionAlgId(dd, 0, &(val)->keyEncryptionAlgorithm))
  3437. return 0;
  3438. if (!ASN1Dec_RecipientEncryptedKeys(dd, 0, &(val)->recipientEncryptedKeys))
  3439. return 0;
  3440. if (!ASN1BERDecEndOfContents(dec, dd, di))
  3441. return 0;
  3442. return 1;
  3443. }
  3444. static void ASN1CALL ASN1Free_KeyAgreeRecipientInfo(KeyAgreeRecipientInfo *val)
  3445. {
  3446. if (val) {
  3447. ASN1Free_OriginatorIdentifierOrKey(&(val)->originator);
  3448. if ((val)->o[0] & 0x80) {
  3449. ASN1octetstring_free(&(val)->ukm);
  3450. }
  3451. ASN1Free_KeyEncryptionAlgId(&(val)->keyEncryptionAlgorithm);
  3452. ASN1Free_RecipientEncryptedKeys(&(val)->recipientEncryptedKeys);
  3453. }
  3454. }
  3455. static int ASN1CALL ASN1Enc_RecipientIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, RecipientIdentifier *val)
  3456. {
  3457. switch ((val)->choice) {
  3458. case 1:
  3459. if (!ASN1Enc_IssuerAndSerialNumber(enc, 0, &(val)->u.issuerAndSerialNumber))
  3460. return 0;
  3461. break;
  3462. case 2:
  3463. if (!ASN1Enc_RecipientKeyIdentifier(enc, 0x80000000, &(val)->u.rKeyId))
  3464. return 0;
  3465. break;
  3466. }
  3467. return 1;
  3468. }
  3469. static int ASN1CALL ASN1Dec_RecipientIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, RecipientIdentifier *val)
  3470. {
  3471. ASN1uint32_t t;
  3472. if (!ASN1BERDecPeekTag(dec, &t))
  3473. return 0;
  3474. switch (t) {
  3475. case 0x10:
  3476. (val)->choice = 1;
  3477. if (!ASN1Dec_IssuerAndSerialNumber(dec, 0, &(val)->u.issuerAndSerialNumber))
  3478. return 0;
  3479. break;
  3480. case 0x80000000:
  3481. (val)->choice = 2;
  3482. if (!ASN1Dec_RecipientKeyIdentifier(dec, 0x80000000, &(val)->u.rKeyId))
  3483. return 0;
  3484. break;
  3485. default:
  3486. ASN1DecSetError(dec, ASN1_ERR_CORRUPT);
  3487. return 0;
  3488. }
  3489. return 1;
  3490. }
  3491. static void ASN1CALL ASN1Free_RecipientIdentifier(RecipientIdentifier *val)
  3492. {
  3493. if (val) {
  3494. switch ((val)->choice) {
  3495. case 1:
  3496. ASN1Free_IssuerAndSerialNumber(&(val)->u.issuerAndSerialNumber);
  3497. break;
  3498. case 2:
  3499. ASN1Free_RecipientKeyIdentifier(&(val)->u.rKeyId);
  3500. break;
  3501. }
  3502. }
  3503. }
  3504. static int ASN1CALL ASN1Enc_CmsRecipientInfo(ASN1encoding_t enc, ASN1uint32_t tag, CmsRecipientInfo *val)
  3505. {
  3506. switch ((val)->choice) {
  3507. case 1:
  3508. if (!ASN1Enc_KeyTransRecipientInfo(enc, 0, &(val)->u.keyTransRecipientInfo))
  3509. return 0;
  3510. break;
  3511. case 2:
  3512. if (!ASN1Enc_KeyAgreeRecipientInfo(enc, 0x80000001, &(val)->u.keyAgreeRecipientInfo))
  3513. return 0;
  3514. break;
  3515. case 3:
  3516. if (!ASN1Enc_MailListRecipientInfo(enc, 0x80000002, &(val)->u.mailListRecipientInfo))
  3517. return 0;
  3518. break;
  3519. }
  3520. return 1;
  3521. }
  3522. static int ASN1CALL ASN1Dec_CmsRecipientInfo(ASN1decoding_t dec, ASN1uint32_t tag, CmsRecipientInfo *val)
  3523. {
  3524. ASN1uint32_t t;
  3525. if (!ASN1BERDecPeekTag(dec, &t))
  3526. return 0;
  3527. switch (t) {
  3528. case 0x10:
  3529. (val)->choice = 1;
  3530. if (!ASN1Dec_KeyTransRecipientInfo(dec, 0, &(val)->u.keyTransRecipientInfo))
  3531. return 0;
  3532. break;
  3533. case 0x80000001:
  3534. (val)->choice = 2;
  3535. if (!ASN1Dec_KeyAgreeRecipientInfo(dec, 0x80000001, &(val)->u.keyAgreeRecipientInfo))
  3536. return 0;
  3537. break;
  3538. case 0x80000002:
  3539. (val)->choice = 3;
  3540. if (!ASN1Dec_MailListRecipientInfo(dec, 0x80000002, &(val)->u.mailListRecipientInfo))
  3541. return 0;
  3542. break;
  3543. default:
  3544. ASN1DecSetError(dec, ASN1_ERR_CORRUPT);
  3545. return 0;
  3546. }
  3547. return 1;
  3548. }
  3549. static void ASN1CALL ASN1Free_CmsRecipientInfo(CmsRecipientInfo *val)
  3550. {
  3551. if (val) {
  3552. switch ((val)->choice) {
  3553. case 1:
  3554. ASN1Free_KeyTransRecipientInfo(&(val)->u.keyTransRecipientInfo);
  3555. break;
  3556. case 2:
  3557. ASN1Free_KeyAgreeRecipientInfo(&(val)->u.keyAgreeRecipientInfo);
  3558. break;
  3559. case 3:
  3560. ASN1Free_MailListRecipientInfo(&(val)->u.mailListRecipientInfo);
  3561. break;
  3562. }
  3563. }
  3564. }
  3565. static int ASN1CALL ASN1Enc_RecipientEncryptedKey(ASN1encoding_t enc, ASN1uint32_t tag, RecipientEncryptedKey *val)
  3566. {
  3567. ASN1uint32_t nLenOff;
  3568. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  3569. return 0;
  3570. if (!ASN1Enc_RecipientIdentifier(enc, 0, &(val)->rid))
  3571. return 0;
  3572. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->encryptedKey).length, ((val)->encryptedKey).value))
  3573. return 0;
  3574. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  3575. return 0;
  3576. return 1;
  3577. }
  3578. static int ASN1CALL ASN1Dec_RecipientEncryptedKey(ASN1decoding_t dec, ASN1uint32_t tag, RecipientEncryptedKey *val)
  3579. {
  3580. ASN1decoding_t dd;
  3581. ASN1octet_t *di;
  3582. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  3583. return 0;
  3584. if (!ASN1Dec_RecipientIdentifier(dd, 0, &(val)->rid))
  3585. return 0;
  3586. if (!ASN1BERDecOctetString(dd, 0x4, &(val)->encryptedKey))
  3587. return 0;
  3588. if (!ASN1BERDecEndOfContents(dec, dd, di))
  3589. return 0;
  3590. return 1;
  3591. }
  3592. static void ASN1CALL ASN1Free_RecipientEncryptedKey(RecipientEncryptedKey *val)
  3593. {
  3594. if (val) {
  3595. ASN1Free_RecipientIdentifier(&(val)->rid);
  3596. ASN1octetstring_free(&(val)->encryptedKey);
  3597. }
  3598. }