Leaked source code of windows server 2003
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.

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