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.

2006 lines
64 KiB

  1. /* Copyright (C) Microsoft Corporation, 1996-1999. All rights reserved. */
  2. /* ASN.1 definitions for PFXNSCP */
  3. #include <windows.h>
  4. #include "pfxnscp.h"
  5. ASN1module_t PFXNSCP_Module = NULL;
  6. static int ASN1CALL ASN1Enc_RSAData(ASN1encoding_t enc, ASN1uint32_t tag, RSAData *val);
  7. static int ASN1CALL ASN1Enc_BaggageItem_unencryptedSecrets(ASN1encoding_t enc, ASN1uint32_t tag, BaggageItem_unencryptedSecrets *val);
  8. static int ASN1CALL ASN1Enc_BaggageItem_espvks(ASN1encoding_t enc, ASN1uint32_t tag, BaggageItem_espvks *val);
  9. static int ASN1CALL ASN1Enc_ContentInfo(ASN1encoding_t enc, ASN1uint32_t tag, ContentInfo *val);
  10. static int ASN1CALL ASN1Enc_Attributes(ASN1encoding_t enc, ASN1uint32_t tag, Attributes *val);
  11. static int ASN1CALL ASN1Enc_AlgorithmIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, AlgorithmIdentifier *val);
  12. static int ASN1CALL ASN1Enc_PBEParameter(ASN1encoding_t enc, ASN1uint32_t tag, PBEParameter *val);
  13. static int ASN1CALL ASN1Enc_DigestAlgorithmIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, DigestAlgorithmIdentifier *val);
  14. static int ASN1CALL ASN1Enc_Baggage(ASN1encoding_t enc, ASN1uint32_t tag, Baggage *val);
  15. static int ASN1CALL ASN1Enc_BaggageItem(ASN1encoding_t enc, ASN1uint32_t tag, BaggageItem *val);
  16. static int ASN1CALL ASN1Enc_PvkAdditional(ASN1encoding_t enc, ASN1uint32_t tag, PvkAdditional *val);
  17. static int ASN1CALL ASN1Enc_SafeContents(ASN1encoding_t enc, ASN1uint32_t tag, SafeContents *val);
  18. static int ASN1CALL ASN1Enc_SafeBag(ASN1encoding_t enc, ASN1uint32_t tag, SafeBag *val);
  19. static int ASN1CALL ASN1Enc_KeyBag(ASN1encoding_t enc, ASN1uint32_t tag, KeyBag *val);
  20. static int ASN1CALL ASN1Enc_CertCRLBag(ASN1encoding_t enc, ASN1uint32_t tag, CertCRLBag *val);
  21. static int ASN1CALL ASN1Enc_CertCRL(ASN1encoding_t enc, ASN1uint32_t tag, CertCRL *val);
  22. static int ASN1CALL ASN1Enc_X509Bag(ASN1encoding_t enc, ASN1uint32_t tag, X509Bag *val);
  23. static int ASN1CALL ASN1Enc_SDSICertBag(ASN1encoding_t enc, ASN1uint32_t tag, SDSICertBag *val);
  24. static int ASN1CALL ASN1Enc_SecretBag(ASN1encoding_t enc, ASN1uint32_t tag, SecretBag *val);
  25. static int ASN1CALL ASN1Enc_SecretAdditional(ASN1encoding_t enc, ASN1uint32_t tag, SecretAdditional *val);
  26. static int ASN1CALL ASN1Enc_PrivateKeyAlgorithmIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, PrivateKeyAlgorithmIdentifier *val);
  27. static int ASN1CALL ASN1Enc_EncryptionAlgorithmIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, EncryptionAlgorithmIdentifier *val);
  28. static int ASN1CALL ASN1Enc_ContentEncryptionAlgorithmIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, ContentEncryptionAlgorithmIdentifier *val);
  29. static int ASN1CALL ASN1Enc_DigestInfo(ASN1encoding_t enc, ASN1uint32_t tag, DigestInfo *val);
  30. static int ASN1CALL ASN1Enc_MacData(ASN1encoding_t enc, ASN1uint32_t tag, MacData *val);
  31. static int ASN1CALL ASN1Enc_AuthenticatedSafe(ASN1encoding_t enc, ASN1uint32_t tag, AuthenticatedSafe *val);
  32. static int ASN1CALL ASN1Enc_Thumbprint(ASN1encoding_t enc, ASN1uint32_t tag, Thumbprint *val);
  33. static int ASN1CALL ASN1Enc_Secret(ASN1encoding_t enc, ASN1uint32_t tag, Secret *val);
  34. static int ASN1CALL ASN1Enc_PVKSupportingData_assocCerts(ASN1encoding_t enc, ASN1uint32_t tag, PVKSupportingData_assocCerts *val);
  35. static int ASN1CALL ASN1Enc_PrivateKeyInfo(ASN1encoding_t enc, ASN1uint32_t tag, PrivateKeyInfo *val);
  36. static int ASN1CALL ASN1Enc_EncryptedContentInfo(ASN1encoding_t enc, ASN1uint32_t tag, EncryptedContentInfo *val);
  37. static int ASN1CALL ASN1Enc_PFX(ASN1encoding_t enc, ASN1uint32_t tag, PFX *val);
  38. static int ASN1CALL ASN1Enc_PVKSupportingData(ASN1encoding_t enc, ASN1uint32_t tag, PVKSupportingData *val);
  39. static int ASN1CALL ASN1Enc_PrivateKey(ASN1encoding_t enc, ASN1uint32_t tag, PrivateKey *val);
  40. static int ASN1CALL ASN1Enc_EncryptedData(ASN1encoding_t enc, ASN1uint32_t tag, EncryptedData *val);
  41. static int ASN1CALL ASN1Enc_ESPVK(ASN1encoding_t enc, ASN1uint32_t tag, ESPVK *val);
  42. static int ASN1CALL ASN1Enc_EncryptedPrivateKeyInfo(ASN1encoding_t enc, ASN1uint32_t tag, EncryptedPrivateKeyInfo *val);
  43. static int ASN1CALL ASN1Dec_RSAData(ASN1decoding_t dec, ASN1uint32_t tag, RSAData *val);
  44. static int ASN1CALL ASN1Dec_BaggageItem_unencryptedSecrets(ASN1decoding_t dec, ASN1uint32_t tag, BaggageItem_unencryptedSecrets *val);
  45. static int ASN1CALL ASN1Dec_BaggageItem_espvks(ASN1decoding_t dec, ASN1uint32_t tag, BaggageItem_espvks *val);
  46. static int ASN1CALL ASN1Dec_ContentInfo(ASN1decoding_t dec, ASN1uint32_t tag, ContentInfo *val);
  47. static int ASN1CALL ASN1Dec_Attributes(ASN1decoding_t dec, ASN1uint32_t tag, Attributes *val);
  48. static int ASN1CALL ASN1Dec_AlgorithmIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, AlgorithmIdentifier *val);
  49. static int ASN1CALL ASN1Dec_PBEParameter(ASN1decoding_t dec, ASN1uint32_t tag, PBEParameter *val);
  50. static int ASN1CALL ASN1Dec_DigestAlgorithmIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, DigestAlgorithmIdentifier *val);
  51. static int ASN1CALL ASN1Dec_Baggage(ASN1decoding_t dec, ASN1uint32_t tag, Baggage *val);
  52. static int ASN1CALL ASN1Dec_BaggageItem(ASN1decoding_t dec, ASN1uint32_t tag, BaggageItem *val);
  53. static int ASN1CALL ASN1Dec_PvkAdditional(ASN1decoding_t dec, ASN1uint32_t tag, PvkAdditional *val);
  54. static int ASN1CALL ASN1Dec_SafeContents(ASN1decoding_t dec, ASN1uint32_t tag, SafeContents *val);
  55. static int ASN1CALL ASN1Dec_SafeBag(ASN1decoding_t dec, ASN1uint32_t tag, SafeBag *val);
  56. static int ASN1CALL ASN1Dec_KeyBag(ASN1decoding_t dec, ASN1uint32_t tag, KeyBag *val);
  57. static int ASN1CALL ASN1Dec_CertCRLBag(ASN1decoding_t dec, ASN1uint32_t tag, CertCRLBag *val);
  58. static int ASN1CALL ASN1Dec_CertCRL(ASN1decoding_t dec, ASN1uint32_t tag, CertCRL *val);
  59. static int ASN1CALL ASN1Dec_X509Bag(ASN1decoding_t dec, ASN1uint32_t tag, X509Bag *val);
  60. static int ASN1CALL ASN1Dec_SDSICertBag(ASN1decoding_t dec, ASN1uint32_t tag, SDSICertBag *val);
  61. static int ASN1CALL ASN1Dec_SecretBag(ASN1decoding_t dec, ASN1uint32_t tag, SecretBag *val);
  62. static int ASN1CALL ASN1Dec_SecretAdditional(ASN1decoding_t dec, ASN1uint32_t tag, SecretAdditional *val);
  63. static int ASN1CALL ASN1Dec_PrivateKeyAlgorithmIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, PrivateKeyAlgorithmIdentifier *val);
  64. static int ASN1CALL ASN1Dec_EncryptionAlgorithmIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, EncryptionAlgorithmIdentifier *val);
  65. static int ASN1CALL ASN1Dec_ContentEncryptionAlgorithmIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, ContentEncryptionAlgorithmIdentifier *val);
  66. static int ASN1CALL ASN1Dec_DigestInfo(ASN1decoding_t dec, ASN1uint32_t tag, DigestInfo *val);
  67. static int ASN1CALL ASN1Dec_MacData(ASN1decoding_t dec, ASN1uint32_t tag, MacData *val);
  68. static int ASN1CALL ASN1Dec_AuthenticatedSafe(ASN1decoding_t dec, ASN1uint32_t tag, AuthenticatedSafe *val);
  69. static int ASN1CALL ASN1Dec_Thumbprint(ASN1decoding_t dec, ASN1uint32_t tag, Thumbprint *val);
  70. static int ASN1CALL ASN1Dec_Secret(ASN1decoding_t dec, ASN1uint32_t tag, Secret *val);
  71. static int ASN1CALL ASN1Dec_PVKSupportingData_assocCerts(ASN1decoding_t dec, ASN1uint32_t tag, PVKSupportingData_assocCerts *val);
  72. static int ASN1CALL ASN1Dec_PrivateKeyInfo(ASN1decoding_t dec, ASN1uint32_t tag, PrivateKeyInfo *val);
  73. static int ASN1CALL ASN1Dec_EncryptedContentInfo(ASN1decoding_t dec, ASN1uint32_t tag, EncryptedContentInfo *val);
  74. static int ASN1CALL ASN1Dec_PFX(ASN1decoding_t dec, ASN1uint32_t tag, PFX *val);
  75. static int ASN1CALL ASN1Dec_PVKSupportingData(ASN1decoding_t dec, ASN1uint32_t tag, PVKSupportingData *val);
  76. static int ASN1CALL ASN1Dec_PrivateKey(ASN1decoding_t dec, ASN1uint32_t tag, PrivateKey *val);
  77. static int ASN1CALL ASN1Dec_EncryptedData(ASN1decoding_t dec, ASN1uint32_t tag, EncryptedData *val);
  78. static int ASN1CALL ASN1Dec_ESPVK(ASN1decoding_t dec, ASN1uint32_t tag, ESPVK *val);
  79. static int ASN1CALL ASN1Dec_EncryptedPrivateKeyInfo(ASN1decoding_t dec, ASN1uint32_t tag, EncryptedPrivateKeyInfo *val);
  80. static void ASN1CALL ASN1Free_RSAData(RSAData *val);
  81. static void ASN1CALL ASN1Free_BaggageItem_unencryptedSecrets(BaggageItem_unencryptedSecrets *val);
  82. static void ASN1CALL ASN1Free_BaggageItem_espvks(BaggageItem_espvks *val);
  83. static void ASN1CALL ASN1Free_ContentInfo(ContentInfo *val);
  84. static void ASN1CALL ASN1Free_Attributes(Attributes *val);
  85. static void ASN1CALL ASN1Free_AlgorithmIdentifier(AlgorithmIdentifier *val);
  86. static void ASN1CALL ASN1Free_PBEParameter(PBEParameter *val);
  87. static void ASN1CALL ASN1Free_DigestAlgorithmIdentifier(DigestAlgorithmIdentifier *val);
  88. static void ASN1CALL ASN1Free_Baggage(Baggage *val);
  89. static void ASN1CALL ASN1Free_BaggageItem(BaggageItem *val);
  90. static void ASN1CALL ASN1Free_PvkAdditional(PvkAdditional *val);
  91. static void ASN1CALL ASN1Free_SafeContents(SafeContents *val);
  92. static void ASN1CALL ASN1Free_SafeBag(SafeBag *val);
  93. static void ASN1CALL ASN1Free_KeyBag(KeyBag *val);
  94. static void ASN1CALL ASN1Free_CertCRLBag(CertCRLBag *val);
  95. static void ASN1CALL ASN1Free_CertCRL(CertCRL *val);
  96. static void ASN1CALL ASN1Free_X509Bag(X509Bag *val);
  97. static void ASN1CALL ASN1Free_SDSICertBag(SDSICertBag *val);
  98. static void ASN1CALL ASN1Free_SecretBag(SecretBag *val);
  99. static void ASN1CALL ASN1Free_SecretAdditional(SecretAdditional *val);
  100. static void ASN1CALL ASN1Free_PrivateKeyAlgorithmIdentifier(PrivateKeyAlgorithmIdentifier *val);
  101. static void ASN1CALL ASN1Free_EncryptionAlgorithmIdentifier(EncryptionAlgorithmIdentifier *val);
  102. static void ASN1CALL ASN1Free_ContentEncryptionAlgorithmIdentifier(ContentEncryptionAlgorithmIdentifier *val);
  103. static void ASN1CALL ASN1Free_DigestInfo(DigestInfo *val);
  104. static void ASN1CALL ASN1Free_MacData(MacData *val);
  105. static void ASN1CALL ASN1Free_AuthenticatedSafe(AuthenticatedSafe *val);
  106. static void ASN1CALL ASN1Free_Thumbprint(Thumbprint *val);
  107. static void ASN1CALL ASN1Free_Secret(Secret *val);
  108. static void ASN1CALL ASN1Free_PVKSupportingData_assocCerts(PVKSupportingData_assocCerts *val);
  109. static void ASN1CALL ASN1Free_PrivateKeyInfo(PrivateKeyInfo *val);
  110. static void ASN1CALL ASN1Free_EncryptedContentInfo(EncryptedContentInfo *val);
  111. static void ASN1CALL ASN1Free_PFX(PFX *val);
  112. static void ASN1CALL ASN1Free_PVKSupportingData(PVKSupportingData *val);
  113. static void ASN1CALL ASN1Free_PrivateKey(PrivateKey *val);
  114. static void ASN1CALL ASN1Free_EncryptedData(EncryptedData *val);
  115. static void ASN1CALL ASN1Free_ESPVK(ESPVK *val);
  116. static void ASN1CALL ASN1Free_EncryptedPrivateKeyInfo(EncryptedPrivateKeyInfo *val);
  117. typedef ASN1BerEncFun_t ASN1EncFun_t;
  118. static const ASN1EncFun_t encfntab[22] = {
  119. (ASN1EncFun_t) ASN1Enc_RSAData,
  120. (ASN1EncFun_t) ASN1Enc_Attributes,
  121. (ASN1EncFun_t) ASN1Enc_PBEParameter,
  122. (ASN1EncFun_t) ASN1Enc_PvkAdditional,
  123. (ASN1EncFun_t) ASN1Enc_SafeContents,
  124. (ASN1EncFun_t) ASN1Enc_SafeBag,
  125. (ASN1EncFun_t) ASN1Enc_KeyBag,
  126. (ASN1EncFun_t) ASN1Enc_CertCRLBag,
  127. (ASN1EncFun_t) ASN1Enc_CertCRL,
  128. (ASN1EncFun_t) ASN1Enc_X509Bag,
  129. (ASN1EncFun_t) ASN1Enc_SDSICertBag,
  130. (ASN1EncFun_t) ASN1Enc_SecretBag,
  131. (ASN1EncFun_t) ASN1Enc_SecretAdditional,
  132. (ASN1EncFun_t) ASN1Enc_AuthenticatedSafe,
  133. (ASN1EncFun_t) ASN1Enc_Secret,
  134. (ASN1EncFun_t) ASN1Enc_PrivateKeyInfo,
  135. (ASN1EncFun_t) ASN1Enc_PFX,
  136. (ASN1EncFun_t) ASN1Enc_PVKSupportingData,
  137. (ASN1EncFun_t) ASN1Enc_PrivateKey,
  138. (ASN1EncFun_t) ASN1Enc_EncryptedData,
  139. (ASN1EncFun_t) ASN1Enc_ESPVK,
  140. (ASN1EncFun_t) ASN1Enc_EncryptedPrivateKeyInfo,
  141. };
  142. typedef ASN1BerDecFun_t ASN1DecFun_t;
  143. static const ASN1DecFun_t decfntab[22] = {
  144. (ASN1DecFun_t) ASN1Dec_RSAData,
  145. (ASN1DecFun_t) ASN1Dec_Attributes,
  146. (ASN1DecFun_t) ASN1Dec_PBEParameter,
  147. (ASN1DecFun_t) ASN1Dec_PvkAdditional,
  148. (ASN1DecFun_t) ASN1Dec_SafeContents,
  149. (ASN1DecFun_t) ASN1Dec_SafeBag,
  150. (ASN1DecFun_t) ASN1Dec_KeyBag,
  151. (ASN1DecFun_t) ASN1Dec_CertCRLBag,
  152. (ASN1DecFun_t) ASN1Dec_CertCRL,
  153. (ASN1DecFun_t) ASN1Dec_X509Bag,
  154. (ASN1DecFun_t) ASN1Dec_SDSICertBag,
  155. (ASN1DecFun_t) ASN1Dec_SecretBag,
  156. (ASN1DecFun_t) ASN1Dec_SecretAdditional,
  157. (ASN1DecFun_t) ASN1Dec_AuthenticatedSafe,
  158. (ASN1DecFun_t) ASN1Dec_Secret,
  159. (ASN1DecFun_t) ASN1Dec_PrivateKeyInfo,
  160. (ASN1DecFun_t) ASN1Dec_PFX,
  161. (ASN1DecFun_t) ASN1Dec_PVKSupportingData,
  162. (ASN1DecFun_t) ASN1Dec_PrivateKey,
  163. (ASN1DecFun_t) ASN1Dec_EncryptedData,
  164. (ASN1DecFun_t) ASN1Dec_ESPVK,
  165. (ASN1DecFun_t) ASN1Dec_EncryptedPrivateKeyInfo,
  166. };
  167. static const ASN1FreeFun_t freefntab[22] = {
  168. (ASN1FreeFun_t) ASN1Free_RSAData,
  169. (ASN1FreeFun_t) ASN1Free_Attributes,
  170. (ASN1FreeFun_t) ASN1Free_PBEParameter,
  171. (ASN1FreeFun_t) ASN1Free_PvkAdditional,
  172. (ASN1FreeFun_t) ASN1Free_SafeContents,
  173. (ASN1FreeFun_t) ASN1Free_SafeBag,
  174. (ASN1FreeFun_t) ASN1Free_KeyBag,
  175. (ASN1FreeFun_t) ASN1Free_CertCRLBag,
  176. (ASN1FreeFun_t) ASN1Free_CertCRL,
  177. (ASN1FreeFun_t) ASN1Free_X509Bag,
  178. (ASN1FreeFun_t) ASN1Free_SDSICertBag,
  179. (ASN1FreeFun_t) ASN1Free_SecretBag,
  180. (ASN1FreeFun_t) ASN1Free_SecretAdditional,
  181. (ASN1FreeFun_t) ASN1Free_AuthenticatedSafe,
  182. (ASN1FreeFun_t) ASN1Free_Secret,
  183. (ASN1FreeFun_t) ASN1Free_PrivateKeyInfo,
  184. (ASN1FreeFun_t) ASN1Free_PFX,
  185. (ASN1FreeFun_t) ASN1Free_PVKSupportingData,
  186. (ASN1FreeFun_t) ASN1Free_PrivateKey,
  187. (ASN1FreeFun_t) ASN1Free_EncryptedData,
  188. (ASN1FreeFun_t) ASN1Free_ESPVK,
  189. (ASN1FreeFun_t) ASN1Free_EncryptedPrivateKeyInfo,
  190. };
  191. static const ULONG sizetab[22] = {
  192. SIZE_PFXNSCP_Module_PDU_0,
  193. SIZE_PFXNSCP_Module_PDU_1,
  194. SIZE_PFXNSCP_Module_PDU_2,
  195. SIZE_PFXNSCP_Module_PDU_3,
  196. SIZE_PFXNSCP_Module_PDU_4,
  197. SIZE_PFXNSCP_Module_PDU_5,
  198. SIZE_PFXNSCP_Module_PDU_6,
  199. SIZE_PFXNSCP_Module_PDU_7,
  200. SIZE_PFXNSCP_Module_PDU_8,
  201. SIZE_PFXNSCP_Module_PDU_9,
  202. SIZE_PFXNSCP_Module_PDU_10,
  203. SIZE_PFXNSCP_Module_PDU_11,
  204. SIZE_PFXNSCP_Module_PDU_12,
  205. SIZE_PFXNSCP_Module_PDU_13,
  206. SIZE_PFXNSCP_Module_PDU_14,
  207. SIZE_PFXNSCP_Module_PDU_15,
  208. SIZE_PFXNSCP_Module_PDU_16,
  209. SIZE_PFXNSCP_Module_PDU_17,
  210. SIZE_PFXNSCP_Module_PDU_18,
  211. SIZE_PFXNSCP_Module_PDU_19,
  212. SIZE_PFXNSCP_Module_PDU_20,
  213. SIZE_PFXNSCP_Module_PDU_21,
  214. };
  215. /* forward declarations of values: */
  216. /* definitions of value components: */
  217. ASN1objectidentifier2_t rsa1 = {
  218. 4, { 1, 2, 840, 113549 }
  219. };
  220. ASN1objectidentifier2_t pkcs_12 = {
  221. 6, { 1, 2, 840, 113549, 1, 12 }
  222. };
  223. ASN1objectidentifier2_t pkcs_12ModeIds = {
  224. 7, { 1, 2, 840, 113549, 1, 12, 1 }
  225. };
  226. ASN1objectidentifier2_t off_lineTransportMode = {
  227. 8, { 1, 2, 840, 113549, 1, 12, 1, 1 }
  228. };
  229. /* definitions of values: */
  230. ASN1bool_t PVKSupportingData_regenerable_default = 0;
  231. Version AuthenticatedSafe_version_default = 1;
  232. void ASN1CALL PFXNSCP_Module_Startup(void)
  233. {
  234. PFXNSCP_Module = ASN1_CreateModule(0x10000, ASN1_BER_RULE_DER, ASN1FLAGS_NOASSERT, 22, (const ASN1GenericFun_t *) encfntab, (const ASN1GenericFun_t *) decfntab, freefntab, sizetab, 0x6e786670);
  235. }
  236. void ASN1CALL PFXNSCP_Module_Cleanup(void)
  237. {
  238. ASN1_CloseModule(PFXNSCP_Module);
  239. PFXNSCP_Module = NULL;
  240. }
  241. static int ASN1CALL ASN1Enc_RSAData(ASN1encoding_t enc, ASN1uint32_t tag, RSAData *val)
  242. {
  243. if (!ASN1DEREncOctetString(enc, tag ? tag : 0x4, (val)->length, (val)->value))
  244. return 0;
  245. return 1;
  246. }
  247. static int ASN1CALL ASN1Dec_RSAData(ASN1decoding_t dec, ASN1uint32_t tag, RSAData *val)
  248. {
  249. if (!ASN1BERDecOctetString(dec, tag ? tag : 0x4, val))
  250. return 0;
  251. return 1;
  252. }
  253. static void ASN1CALL ASN1Free_RSAData(RSAData *val)
  254. {
  255. if (val) {
  256. ASN1octetstring_free(val);
  257. }
  258. }
  259. static int ASN1CALL ASN1Enc_BaggageItem_unencryptedSecrets(ASN1encoding_t enc, ASN1uint32_t tag, BaggageItem_unencryptedSecrets *val)
  260. {
  261. ASN1uint32_t nLenOff;
  262. void *pBlk;
  263. ASN1uint32_t i;
  264. ASN1encoding_t enc2;
  265. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  266. return 0;
  267. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  268. return 0;
  269. for (i = 0; i < (val)->count; i++) {
  270. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  271. return 0;
  272. if (!ASN1Enc_SafeBag(enc2, 0, &((val)->value)[i]))
  273. return 0;
  274. if (!ASN1DEREncFlushBlkElement(pBlk))
  275. return 0;
  276. }
  277. if (!ASN1DEREncEndBlk(pBlk))
  278. return 0;
  279. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  280. return 0;
  281. return 1;
  282. }
  283. static int ASN1CALL ASN1Dec_BaggageItem_unencryptedSecrets(ASN1decoding_t dec, ASN1uint32_t tag, BaggageItem_unencryptedSecrets *val)
  284. {
  285. ASN1decoding_t dd;
  286. ASN1octet_t *di;
  287. ASN1uint32_t t;
  288. ASN1uint32_t n;
  289. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  290. return 0;
  291. (val)->count = n = 0;
  292. (val)->value = NULL;
  293. while (ASN1BERDecNotEndOfContents(dd, di)) {
  294. if (!ASN1BERDecPeekTag(dd, &t))
  295. return 0;
  296. if ((val)->count >= n) {
  297. void *pvASN1DecRealloc;
  298. n = n ? (n << 1) : 16;
  299. if (!(pvASN1DecRealloc = ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  300. return 0;
  301. (val)->value = (SafeBag *) pvASN1DecRealloc;
  302. }
  303. if (!ASN1Dec_SafeBag(dd, 0, &((val)->value)[(val)->count]))
  304. return 0;
  305. ((val)->count)++;
  306. }
  307. if (!ASN1BERDecEndOfContents(dec, dd, di))
  308. return 0;
  309. return 1;
  310. }
  311. static void ASN1CALL ASN1Free_BaggageItem_unencryptedSecrets(BaggageItem_unencryptedSecrets *val)
  312. {
  313. ASN1uint32_t i;
  314. if (val) {
  315. ASN1Free_SafeBag(&(val)->value[0]);
  316. for (i = 1; i < (val)->count; i++) {
  317. ASN1Free_SafeBag(&(val)->value[i]);
  318. }
  319. ASN1Free((val)->value);
  320. }
  321. }
  322. static int ASN1CALL ASN1Enc_BaggageItem_espvks(ASN1encoding_t enc, ASN1uint32_t tag, BaggageItem_espvks *val)
  323. {
  324. ASN1uint32_t nLenOff;
  325. void *pBlk;
  326. ASN1uint32_t i;
  327. ASN1encoding_t enc2;
  328. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  329. return 0;
  330. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  331. return 0;
  332. for (i = 0; i < (val)->count; i++) {
  333. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  334. return 0;
  335. if (!ASN1Enc_ESPVK(enc2, 0, &((val)->value)[i]))
  336. return 0;
  337. if (!ASN1DEREncFlushBlkElement(pBlk))
  338. return 0;
  339. }
  340. if (!ASN1DEREncEndBlk(pBlk))
  341. return 0;
  342. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  343. return 0;
  344. return 1;
  345. }
  346. static int ASN1CALL ASN1Dec_BaggageItem_espvks(ASN1decoding_t dec, ASN1uint32_t tag, BaggageItem_espvks *val)
  347. {
  348. ASN1decoding_t dd;
  349. ASN1octet_t *di;
  350. ASN1uint32_t t;
  351. ASN1uint32_t n;
  352. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  353. return 0;
  354. (val)->count = n = 0;
  355. (val)->value = NULL;
  356. while (ASN1BERDecNotEndOfContents(dd, di)) {
  357. if (!ASN1BERDecPeekTag(dd, &t))
  358. return 0;
  359. if ((val)->count >= n) {
  360. void *pvASN1DecRealloc;
  361. n = n ? (n << 1) : 16;
  362. if (!(pvASN1DecRealloc = ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  363. return 0;
  364. (val)->value = (ESPVK *) pvASN1DecRealloc;
  365. }
  366. if (!ASN1Dec_ESPVK(dd, 0, &((val)->value)[(val)->count]))
  367. return 0;
  368. ((val)->count)++;
  369. }
  370. if (!ASN1BERDecEndOfContents(dec, dd, di))
  371. return 0;
  372. return 1;
  373. }
  374. static void ASN1CALL ASN1Free_BaggageItem_espvks(BaggageItem_espvks *val)
  375. {
  376. ASN1uint32_t i;
  377. if (val) {
  378. ASN1Free_ESPVK(&(val)->value[0]);
  379. for (i = 1; i < (val)->count; i++) {
  380. ASN1Free_ESPVK(&(val)->value[i]);
  381. }
  382. ASN1Free((val)->value);
  383. }
  384. }
  385. static int ASN1CALL ASN1Enc_ContentInfo(ASN1encoding_t enc, ASN1uint32_t tag, ContentInfo *val)
  386. {
  387. ASN1uint32_t nLenOff;
  388. ASN1uint32_t nLenOff0;
  389. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  390. return 0;
  391. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->contentType))
  392. return 0;
  393. if ((val)->o[0] & 0x80) {
  394. if (!ASN1BEREncExplicitTag(enc, 0x80000000, &nLenOff0))
  395. return 0;
  396. if (!ASN1BEREncOpenType(enc, &(val)->content))
  397. return 0;
  398. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  399. return 0;
  400. }
  401. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  402. return 0;
  403. return 1;
  404. }
  405. static int ASN1CALL ASN1Dec_ContentInfo(ASN1decoding_t dec, ASN1uint32_t tag, ContentInfo *val)
  406. {
  407. ASN1decoding_t dd;
  408. ASN1octet_t *di;
  409. ASN1uint32_t t;
  410. ASN1decoding_t dd0;
  411. ASN1octet_t *di0;
  412. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  413. return 0;
  414. ZeroMemory((val)->o, 1);
  415. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->contentType))
  416. return 0;
  417. if (ASN1BERDecPeekTag(dd, &t)) {
  418. if (t == 0x80000000) {
  419. (val)->o[0] |= 0x80;
  420. if (!ASN1BERDecExplicitTag(dd, 0x80000000, &dd0, &di0))
  421. return 0;
  422. if (!ASN1BERDecOpenType(dd0, &(val)->content))
  423. return 0;
  424. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  425. return 0;
  426. }
  427. }
  428. if (!ASN1BERDecEndOfContents(dec, dd, di))
  429. return 0;
  430. return 1;
  431. }
  432. static void ASN1CALL ASN1Free_ContentInfo(ContentInfo *val)
  433. {
  434. if (val) {
  435. if ((val)->o[0] & 0x80) {
  436. ASN1open_free(&(val)->content);
  437. }
  438. }
  439. }
  440. static int ASN1CALL ASN1Enc_Attributes(ASN1encoding_t enc, ASN1uint32_t tag, Attributes *val)
  441. {
  442. ASN1uint32_t nLenOff;
  443. void *pBlk;
  444. ASN1uint32_t i;
  445. ASN1encoding_t enc2;
  446. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  447. return 0;
  448. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  449. return 0;
  450. for (i = 0; i < (val)->count; i++) {
  451. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  452. return 0;
  453. if (!ASN1BEREncOpenType(enc2, &((val)->value)[i]))
  454. return 0;
  455. if (!ASN1DEREncFlushBlkElement(pBlk))
  456. return 0;
  457. }
  458. if (!ASN1DEREncEndBlk(pBlk))
  459. return 0;
  460. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  461. return 0;
  462. return 1;
  463. }
  464. static int ASN1CALL ASN1Dec_Attributes(ASN1decoding_t dec, ASN1uint32_t tag, Attributes *val)
  465. {
  466. ASN1decoding_t dd;
  467. ASN1octet_t *di;
  468. ASN1uint32_t t;
  469. ASN1uint32_t n;
  470. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  471. return 0;
  472. (val)->count = n = 0;
  473. (val)->value = NULL;
  474. while (ASN1BERDecNotEndOfContents(dd, di)) {
  475. if (!ASN1BERDecPeekTag(dd, &t))
  476. return 0;
  477. if ((val)->count >= n) {
  478. void *pvASN1DecRealloc;
  479. n = n ? (n << 1) : 16;
  480. if (!(pvASN1DecRealloc = ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  481. return 0;
  482. (val)->value = (Attribute *) pvASN1DecRealloc;
  483. }
  484. if (!ASN1BERDecOpenType(dd, &((val)->value)[(val)->count]))
  485. return 0;
  486. ((val)->count)++;
  487. }
  488. if (!ASN1BERDecEndOfContents(dec, dd, di))
  489. return 0;
  490. return 1;
  491. }
  492. static void ASN1CALL ASN1Free_Attributes(Attributes *val)
  493. {
  494. ASN1uint32_t i;
  495. if (val) {
  496. ASN1open_free(&(val)->value[0]);
  497. for (i = 1; i < (val)->count; i++) {
  498. ASN1open_free(&(val)->value[i]);
  499. }
  500. ASN1Free((val)->value);
  501. }
  502. }
  503. static int ASN1CALL ASN1Enc_AlgorithmIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, AlgorithmIdentifier *val)
  504. {
  505. ASN1uint32_t nLenOff;
  506. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  507. return 0;
  508. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->algorithm))
  509. return 0;
  510. if ((val)->o[0] & 0x80) {
  511. if (!ASN1BEREncOpenType(enc, &(val)->parameters))
  512. return 0;
  513. }
  514. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  515. return 0;
  516. return 1;
  517. }
  518. static int ASN1CALL ASN1Dec_AlgorithmIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, AlgorithmIdentifier *val)
  519. {
  520. ASN1decoding_t dd;
  521. ASN1octet_t *di;
  522. ASN1uint32_t t;
  523. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  524. return 0;
  525. ZeroMemory((val)->o, 1);
  526. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->algorithm))
  527. return 0;
  528. if (ASN1BERDecPeekTag(dd, &t)) {
  529. (val)->o[0] |= 0x80;
  530. if (!ASN1BERDecOpenType(dd, &(val)->parameters))
  531. return 0;
  532. }
  533. if (!ASN1BERDecEndOfContents(dec, dd, di))
  534. return 0;
  535. return 1;
  536. }
  537. static void ASN1CALL ASN1Free_AlgorithmIdentifier(AlgorithmIdentifier *val)
  538. {
  539. if (val) {
  540. if ((val)->o[0] & 0x80) {
  541. ASN1open_free(&(val)->parameters);
  542. }
  543. }
  544. }
  545. static int ASN1CALL ASN1Enc_PBEParameter(ASN1encoding_t enc, ASN1uint32_t tag, PBEParameter *val)
  546. {
  547. ASN1uint32_t nLenOff;
  548. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  549. return 0;
  550. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->salt).length, ((val)->salt).value))
  551. return 0;
  552. if (!ASN1BEREncS32(enc, 0x2, (val)->iterationCount))
  553. return 0;
  554. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  555. return 0;
  556. return 1;
  557. }
  558. static int ASN1CALL ASN1Dec_PBEParameter(ASN1decoding_t dec, ASN1uint32_t tag, PBEParameter *val)
  559. {
  560. ASN1decoding_t dd;
  561. ASN1octet_t *di;
  562. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  563. return 0;
  564. if (!ASN1BERDecOctetString(dd, 0x4, &(val)->salt))
  565. return 0;
  566. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->iterationCount))
  567. return 0;
  568. if (!ASN1BERDecEndOfContents(dec, dd, di))
  569. return 0;
  570. return 1;
  571. }
  572. static void ASN1CALL ASN1Free_PBEParameter(PBEParameter *val)
  573. {
  574. if (val) {
  575. ASN1octetstring_free(&(val)->salt);
  576. }
  577. }
  578. static int ASN1CALL ASN1Enc_DigestAlgorithmIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, DigestAlgorithmIdentifier *val)
  579. {
  580. if (!ASN1Enc_AlgorithmIdentifier(enc, tag, val))
  581. return 0;
  582. return 1;
  583. }
  584. static int ASN1CALL ASN1Dec_DigestAlgorithmIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, DigestAlgorithmIdentifier *val)
  585. {
  586. if (!ASN1Dec_AlgorithmIdentifier(dec, tag, val))
  587. return 0;
  588. return 1;
  589. }
  590. static void ASN1CALL ASN1Free_DigestAlgorithmIdentifier(DigestAlgorithmIdentifier *val)
  591. {
  592. if (val) {
  593. ASN1Free_AlgorithmIdentifier(val);
  594. }
  595. }
  596. static int ASN1CALL ASN1Enc_Baggage(ASN1encoding_t enc, ASN1uint32_t tag, Baggage *val)
  597. {
  598. ASN1uint32_t nLenOff;
  599. void *pBlk;
  600. ASN1uint32_t i;
  601. ASN1encoding_t enc2;
  602. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  603. return 0;
  604. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  605. return 0;
  606. for (i = 0; i < (val)->count; i++) {
  607. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  608. return 0;
  609. if (!ASN1Enc_BaggageItem(enc2, 0, &((val)->value)[i]))
  610. return 0;
  611. if (!ASN1DEREncFlushBlkElement(pBlk))
  612. return 0;
  613. }
  614. if (!ASN1DEREncEndBlk(pBlk))
  615. return 0;
  616. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  617. return 0;
  618. return 1;
  619. }
  620. static int ASN1CALL ASN1Dec_Baggage(ASN1decoding_t dec, ASN1uint32_t tag, Baggage *val)
  621. {
  622. ASN1decoding_t dd;
  623. ASN1octet_t *di;
  624. ASN1uint32_t t;
  625. ASN1uint32_t n;
  626. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  627. return 0;
  628. (val)->count = n = 0;
  629. (val)->value = NULL;
  630. while (ASN1BERDecNotEndOfContents(dd, di)) {
  631. if (!ASN1BERDecPeekTag(dd, &t))
  632. return 0;
  633. if ((val)->count >= n) {
  634. void *pvASN1DecRealloc;
  635. n = n ? (n << 1) : 16;
  636. if (!(pvASN1DecRealloc = ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  637. return 0;
  638. (val)->value = (BaggageItem *) pvASN1DecRealloc;
  639. }
  640. if (!ASN1Dec_BaggageItem(dd, 0, &((val)->value)[(val)->count]))
  641. return 0;
  642. ((val)->count)++;
  643. }
  644. if (!ASN1BERDecEndOfContents(dec, dd, di))
  645. return 0;
  646. return 1;
  647. }
  648. static void ASN1CALL ASN1Free_Baggage(Baggage *val)
  649. {
  650. ASN1uint32_t i;
  651. if (val) {
  652. ASN1Free_BaggageItem(&(val)->value[0]);
  653. for (i = 1; i < (val)->count; i++) {
  654. ASN1Free_BaggageItem(&(val)->value[i]);
  655. }
  656. ASN1Free((val)->value);
  657. }
  658. }
  659. static int ASN1CALL ASN1Enc_BaggageItem(ASN1encoding_t enc, ASN1uint32_t tag, BaggageItem *val)
  660. {
  661. ASN1uint32_t nLenOff;
  662. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  663. return 0;
  664. if (!ASN1Enc_BaggageItem_espvks(enc, 0, &(val)->espvks))
  665. return 0;
  666. if (!ASN1Enc_BaggageItem_unencryptedSecrets(enc, 0, &(val)->unencryptedSecrets))
  667. return 0;
  668. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  669. return 0;
  670. return 1;
  671. }
  672. static int ASN1CALL ASN1Dec_BaggageItem(ASN1decoding_t dec, ASN1uint32_t tag, BaggageItem *val)
  673. {
  674. ASN1decoding_t dd;
  675. ASN1octet_t *di;
  676. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  677. return 0;
  678. if (!ASN1Dec_BaggageItem_espvks(dd, 0, &(val)->espvks))
  679. return 0;
  680. if (!ASN1Dec_BaggageItem_unencryptedSecrets(dd, 0, &(val)->unencryptedSecrets))
  681. return 0;
  682. if (!ASN1BERDecEndOfContents(dec, dd, di))
  683. return 0;
  684. return 1;
  685. }
  686. static void ASN1CALL ASN1Free_BaggageItem(BaggageItem *val)
  687. {
  688. if (val) {
  689. ASN1Free_BaggageItem_espvks(&(val)->espvks);
  690. ASN1Free_BaggageItem_unencryptedSecrets(&(val)->unencryptedSecrets);
  691. }
  692. }
  693. static int ASN1CALL ASN1Enc_PvkAdditional(ASN1encoding_t enc, ASN1uint32_t tag, PvkAdditional *val)
  694. {
  695. ASN1uint32_t nLenOff;
  696. ASN1uint32_t nLenOff0;
  697. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  698. return 0;
  699. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->pvkAdditionalType))
  700. return 0;
  701. if (!ASN1BEREncExplicitTag(enc, 0x80000000, &nLenOff0))
  702. return 0;
  703. if (!ASN1BEREncOpenType(enc, &(val)->pvkAdditionalContent))
  704. return 0;
  705. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  706. return 0;
  707. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  708. return 0;
  709. return 1;
  710. }
  711. static int ASN1CALL ASN1Dec_PvkAdditional(ASN1decoding_t dec, ASN1uint32_t tag, PvkAdditional *val)
  712. {
  713. ASN1decoding_t dd;
  714. ASN1octet_t *di;
  715. ASN1decoding_t dd0;
  716. ASN1octet_t *di0;
  717. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  718. return 0;
  719. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->pvkAdditionalType))
  720. return 0;
  721. if (!ASN1BERDecExplicitTag(dd, 0x80000000, &dd0, &di0))
  722. return 0;
  723. if (!ASN1BERDecOpenType(dd0, &(val)->pvkAdditionalContent))
  724. return 0;
  725. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  726. return 0;
  727. if (!ASN1BERDecEndOfContents(dec, dd, di))
  728. return 0;
  729. return 1;
  730. }
  731. static void ASN1CALL ASN1Free_PvkAdditional(PvkAdditional *val)
  732. {
  733. if (val) {
  734. ASN1open_free(&(val)->pvkAdditionalContent);
  735. }
  736. }
  737. static int ASN1CALL ASN1Enc_SafeContents(ASN1encoding_t enc, ASN1uint32_t tag, SafeContents *val)
  738. {
  739. ASN1uint32_t nLenOff;
  740. void *pBlk;
  741. ASN1uint32_t i;
  742. ASN1encoding_t enc2;
  743. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  744. return 0;
  745. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  746. return 0;
  747. for (i = 0; i < (val)->count; i++) {
  748. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  749. return 0;
  750. if (!ASN1Enc_SafeBag(enc2, 0, &((val)->value)[i]))
  751. return 0;
  752. if (!ASN1DEREncFlushBlkElement(pBlk))
  753. return 0;
  754. }
  755. if (!ASN1DEREncEndBlk(pBlk))
  756. return 0;
  757. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  758. return 0;
  759. return 1;
  760. }
  761. static int ASN1CALL ASN1Dec_SafeContents(ASN1decoding_t dec, ASN1uint32_t tag, SafeContents *val)
  762. {
  763. ASN1decoding_t dd;
  764. ASN1octet_t *di;
  765. ASN1uint32_t t;
  766. ASN1uint32_t n;
  767. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  768. return 0;
  769. (val)->count = n = 0;
  770. (val)->value = NULL;
  771. while (ASN1BERDecNotEndOfContents(dd, di)) {
  772. if (!ASN1BERDecPeekTag(dd, &t))
  773. return 0;
  774. if ((val)->count >= n) {
  775. void *pvASN1DecRealloc;
  776. n = n ? (n << 1) : 16;
  777. if (!(pvASN1DecRealloc = ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  778. return 0;
  779. (val)->value = (SafeBag *) pvASN1DecRealloc;
  780. }
  781. if (!ASN1Dec_SafeBag(dd, 0, &((val)->value)[(val)->count]))
  782. return 0;
  783. ((val)->count)++;
  784. }
  785. if (!ASN1BERDecEndOfContents(dec, dd, di))
  786. return 0;
  787. return 1;
  788. }
  789. static void ASN1CALL ASN1Free_SafeContents(SafeContents *val)
  790. {
  791. ASN1uint32_t i;
  792. if (val) {
  793. ASN1Free_SafeBag(&(val)->value[0]);
  794. for (i = 1; i < (val)->count; i++) {
  795. ASN1Free_SafeBag(&(val)->value[i]);
  796. }
  797. ASN1Free((val)->value);
  798. }
  799. }
  800. static int ASN1CALL ASN1Enc_SafeBag(ASN1encoding_t enc, ASN1uint32_t tag, SafeBag *val)
  801. {
  802. ASN1uint32_t nLenOff;
  803. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  804. return 0;
  805. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->safeBagType))
  806. return 0;
  807. if (!ASN1BEREncOpenType(enc, &(val)->safeBagContent))
  808. return 0;
  809. if ((val)->o[0] & 0x80) {
  810. if (!ASN1DEREncChar16String(enc, 0x1e, ((val)->safeBagName).length, ((val)->safeBagName).value))
  811. return 0;
  812. }
  813. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  814. return 0;
  815. return 1;
  816. }
  817. static int ASN1CALL ASN1Dec_SafeBag(ASN1decoding_t dec, ASN1uint32_t tag, SafeBag *val)
  818. {
  819. ASN1decoding_t dd;
  820. ASN1octet_t *di;
  821. ASN1uint32_t t;
  822. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  823. return 0;
  824. ZeroMemory((val)->o, 1);
  825. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->safeBagType))
  826. return 0;
  827. if (!ASN1BERDecOpenType(dd, &(val)->safeBagContent))
  828. return 0;
  829. ASN1BERDecPeekTag(dd, &t);
  830. if (t == 0x1e) {
  831. (val)->o[0] |= 0x80;
  832. if (!ASN1BERDecChar16String(dd, 0x1e, &(val)->safeBagName))
  833. return 0;
  834. }
  835. if (!ASN1BERDecEndOfContents(dec, dd, di))
  836. return 0;
  837. return 1;
  838. }
  839. static void ASN1CALL ASN1Free_SafeBag(SafeBag *val)
  840. {
  841. if (val) {
  842. ASN1open_free(&(val)->safeBagContent);
  843. if ((val)->o[0] & 0x80) {
  844. ASN1char16string_free(&(val)->safeBagName);
  845. }
  846. }
  847. }
  848. static int ASN1CALL ASN1Enc_KeyBag(ASN1encoding_t enc, ASN1uint32_t tag, KeyBag *val)
  849. {
  850. ASN1uint32_t nLenOff;
  851. void *pBlk;
  852. ASN1uint32_t i;
  853. ASN1encoding_t enc2;
  854. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  855. return 0;
  856. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  857. return 0;
  858. for (i = 0; i < (val)->count; i++) {
  859. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  860. return 0;
  861. if (!ASN1Enc_PrivateKey(enc2, 0, &((val)->value)[i]))
  862. return 0;
  863. if (!ASN1DEREncFlushBlkElement(pBlk))
  864. return 0;
  865. }
  866. if (!ASN1DEREncEndBlk(pBlk))
  867. return 0;
  868. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  869. return 0;
  870. return 1;
  871. }
  872. static int ASN1CALL ASN1Dec_KeyBag(ASN1decoding_t dec, ASN1uint32_t tag, KeyBag *val)
  873. {
  874. ASN1decoding_t dd;
  875. ASN1octet_t *di;
  876. ASN1uint32_t t;
  877. ASN1uint32_t n;
  878. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  879. return 0;
  880. (val)->count = n = 0;
  881. (val)->value = NULL;
  882. while (ASN1BERDecNotEndOfContents(dd, di)) {
  883. if (!ASN1BERDecPeekTag(dd, &t))
  884. return 0;
  885. if ((val)->count >= n) {
  886. void *pvASN1DecRealloc;
  887. n = n ? (n << 1) : 16;
  888. if (!(pvASN1DecRealloc = ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  889. return 0;
  890. (val)->value = (PrivateKey *) pvASN1DecRealloc;
  891. }
  892. if (!ASN1Dec_PrivateKey(dd, 0, &((val)->value)[(val)->count]))
  893. return 0;
  894. ((val)->count)++;
  895. }
  896. if (!ASN1BERDecEndOfContents(dec, dd, di))
  897. return 0;
  898. return 1;
  899. }
  900. static void ASN1CALL ASN1Free_KeyBag(KeyBag *val)
  901. {
  902. ASN1uint32_t i;
  903. if (val) {
  904. ASN1Free_PrivateKey(&(val)->value[0]);
  905. for (i = 1; i < (val)->count; i++) {
  906. ASN1Free_PrivateKey(&(val)->value[i]);
  907. }
  908. ASN1Free((val)->value);
  909. }
  910. }
  911. static int ASN1CALL ASN1Enc_CertCRLBag(ASN1encoding_t enc, ASN1uint32_t tag, CertCRLBag *val)
  912. {
  913. ASN1uint32_t nLenOff;
  914. void *pBlk;
  915. ASN1uint32_t i;
  916. ASN1encoding_t enc2;
  917. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  918. return 0;
  919. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  920. return 0;
  921. for (i = 0; i < (val)->count; i++) {
  922. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  923. return 0;
  924. if (!ASN1Enc_CertCRL(enc2, 0, &((val)->value)[i]))
  925. return 0;
  926. if (!ASN1DEREncFlushBlkElement(pBlk))
  927. return 0;
  928. }
  929. if (!ASN1DEREncEndBlk(pBlk))
  930. return 0;
  931. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  932. return 0;
  933. return 1;
  934. }
  935. static int ASN1CALL ASN1Dec_CertCRLBag(ASN1decoding_t dec, ASN1uint32_t tag, CertCRLBag *val)
  936. {
  937. ASN1decoding_t dd;
  938. ASN1octet_t *di;
  939. ASN1uint32_t t;
  940. ASN1uint32_t n;
  941. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  942. return 0;
  943. (val)->count = n = 0;
  944. (val)->value = NULL;
  945. while (ASN1BERDecNotEndOfContents(dd, di)) {
  946. if (!ASN1BERDecPeekTag(dd, &t))
  947. return 0;
  948. if ((val)->count >= n) {
  949. void *pvASN1DecRealloc;
  950. n = n ? (n << 1) : 16;
  951. if (!(pvASN1DecRealloc = ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  952. return 0;
  953. (val)->value = (CertCRL *) pvASN1DecRealloc;
  954. }
  955. if (!ASN1Dec_CertCRL(dd, 0, &((val)->value)[(val)->count]))
  956. return 0;
  957. ((val)->count)++;
  958. }
  959. if (!ASN1BERDecEndOfContents(dec, dd, di))
  960. return 0;
  961. return 1;
  962. }
  963. static void ASN1CALL ASN1Free_CertCRLBag(CertCRLBag *val)
  964. {
  965. ASN1uint32_t i;
  966. if (val) {
  967. ASN1Free_CertCRL(&(val)->value[0]);
  968. for (i = 1; i < (val)->count; i++) {
  969. ASN1Free_CertCRL(&(val)->value[i]);
  970. }
  971. ASN1Free((val)->value);
  972. }
  973. }
  974. static int ASN1CALL ASN1Enc_CertCRL(ASN1encoding_t enc, ASN1uint32_t tag, CertCRL *val)
  975. {
  976. ASN1uint32_t nLenOff;
  977. ASN1uint32_t nLenOff0;
  978. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  979. return 0;
  980. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->bagId))
  981. return 0;
  982. if (!ASN1BEREncExplicitTag(enc, 0x80000000, &nLenOff0))
  983. return 0;
  984. if (!ASN1BEREncOpenType(enc, &(val)->value))
  985. return 0;
  986. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  987. return 0;
  988. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  989. return 0;
  990. return 1;
  991. }
  992. static int ASN1CALL ASN1Dec_CertCRL(ASN1decoding_t dec, ASN1uint32_t tag, CertCRL *val)
  993. {
  994. ASN1decoding_t dd;
  995. ASN1octet_t *di;
  996. ASN1decoding_t dd0;
  997. ASN1octet_t *di0;
  998. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  999. return 0;
  1000. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->bagId))
  1001. return 0;
  1002. if (!ASN1BERDecExplicitTag(dd, 0x80000000, &dd0, &di0))
  1003. return 0;
  1004. if (!ASN1BERDecOpenType(dd0, &(val)->value))
  1005. return 0;
  1006. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  1007. return 0;
  1008. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1009. return 0;
  1010. return 1;
  1011. }
  1012. static void ASN1CALL ASN1Free_CertCRL(CertCRL *val)
  1013. {
  1014. if (val) {
  1015. ASN1open_free(&(val)->value);
  1016. }
  1017. }
  1018. static int ASN1CALL ASN1Enc_X509Bag(ASN1encoding_t enc, ASN1uint32_t tag, X509Bag *val)
  1019. {
  1020. ASN1uint32_t nLenOff;
  1021. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1022. return 0;
  1023. if (!ASN1Enc_ContentInfo(enc, 0, &(val)->certOrCRL))
  1024. return 0;
  1025. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1026. return 0;
  1027. return 1;
  1028. }
  1029. static int ASN1CALL ASN1Dec_X509Bag(ASN1decoding_t dec, ASN1uint32_t tag, X509Bag *val)
  1030. {
  1031. ASN1decoding_t dd;
  1032. ASN1octet_t *di;
  1033. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1034. return 0;
  1035. if (!ASN1Dec_ContentInfo(dd, 0, &(val)->certOrCRL))
  1036. return 0;
  1037. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1038. return 0;
  1039. return 1;
  1040. }
  1041. static void ASN1CALL ASN1Free_X509Bag(X509Bag *val)
  1042. {
  1043. if (val) {
  1044. ASN1Free_ContentInfo(&(val)->certOrCRL);
  1045. }
  1046. }
  1047. static int ASN1CALL ASN1Enc_SDSICertBag(ASN1encoding_t enc, ASN1uint32_t tag, SDSICertBag *val)
  1048. {
  1049. ASN1uint32_t nLenOff;
  1050. ASN1uint32_t t;
  1051. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1052. return 0;
  1053. t = lstrlenA((val)->value);
  1054. if (!ASN1DEREncCharString(enc, 0x16, t, (val)->value))
  1055. return 0;
  1056. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1057. return 0;
  1058. return 1;
  1059. }
  1060. static int ASN1CALL ASN1Dec_SDSICertBag(ASN1decoding_t dec, ASN1uint32_t tag, SDSICertBag *val)
  1061. {
  1062. ASN1decoding_t dd;
  1063. ASN1octet_t *di;
  1064. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1065. return 0;
  1066. if (!ASN1BERDecZeroCharString(dd, 0x16, &(val)->value))
  1067. return 0;
  1068. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1069. return 0;
  1070. return 1;
  1071. }
  1072. static void ASN1CALL ASN1Free_SDSICertBag(SDSICertBag *val)
  1073. {
  1074. if (val) {
  1075. ASN1ztcharstring_free((val)->value);
  1076. }
  1077. }
  1078. static int ASN1CALL ASN1Enc_SecretBag(ASN1encoding_t enc, ASN1uint32_t tag, SecretBag *val)
  1079. {
  1080. ASN1uint32_t nLenOff;
  1081. void *pBlk;
  1082. ASN1uint32_t i;
  1083. ASN1encoding_t enc2;
  1084. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  1085. return 0;
  1086. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  1087. return 0;
  1088. for (i = 0; i < (val)->count; i++) {
  1089. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  1090. return 0;
  1091. if (!ASN1Enc_Secret(enc2, 0, &((val)->value)[i]))
  1092. return 0;
  1093. if (!ASN1DEREncFlushBlkElement(pBlk))
  1094. return 0;
  1095. }
  1096. if (!ASN1DEREncEndBlk(pBlk))
  1097. return 0;
  1098. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1099. return 0;
  1100. return 1;
  1101. }
  1102. static int ASN1CALL ASN1Dec_SecretBag(ASN1decoding_t dec, ASN1uint32_t tag, SecretBag *val)
  1103. {
  1104. ASN1decoding_t dd;
  1105. ASN1octet_t *di;
  1106. ASN1uint32_t t;
  1107. ASN1uint32_t n;
  1108. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  1109. return 0;
  1110. (val)->count = n = 0;
  1111. (val)->value = NULL;
  1112. while (ASN1BERDecNotEndOfContents(dd, di)) {
  1113. if (!ASN1BERDecPeekTag(dd, &t))
  1114. return 0;
  1115. if ((val)->count >= n) {
  1116. void *pvASN1DecRealloc;
  1117. n = n ? (n << 1) : 16;
  1118. if (!(pvASN1DecRealloc = ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  1119. return 0;
  1120. (val)->value = (Secret *) pvASN1DecRealloc;
  1121. }
  1122. if (!ASN1Dec_Secret(dd, 0, &((val)->value)[(val)->count]))
  1123. return 0;
  1124. ((val)->count)++;
  1125. }
  1126. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1127. return 0;
  1128. return 1;
  1129. }
  1130. static void ASN1CALL ASN1Free_SecretBag(SecretBag *val)
  1131. {
  1132. ASN1uint32_t i;
  1133. if (val) {
  1134. ASN1Free_Secret(&(val)->value[0]);
  1135. for (i = 1; i < (val)->count; i++) {
  1136. ASN1Free_Secret(&(val)->value[i]);
  1137. }
  1138. ASN1Free((val)->value);
  1139. }
  1140. }
  1141. static int ASN1CALL ASN1Enc_SecretAdditional(ASN1encoding_t enc, ASN1uint32_t tag, SecretAdditional *val)
  1142. {
  1143. ASN1uint32_t nLenOff;
  1144. ASN1uint32_t nLenOff0;
  1145. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1146. return 0;
  1147. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->secretAdditionalType))
  1148. return 0;
  1149. if (!ASN1BEREncExplicitTag(enc, 0x80000000, &nLenOff0))
  1150. return 0;
  1151. if (!ASN1BEREncOpenType(enc, &(val)->secretAdditionalContent))
  1152. return 0;
  1153. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  1154. return 0;
  1155. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1156. return 0;
  1157. return 1;
  1158. }
  1159. static int ASN1CALL ASN1Dec_SecretAdditional(ASN1decoding_t dec, ASN1uint32_t tag, SecretAdditional *val)
  1160. {
  1161. ASN1decoding_t dd;
  1162. ASN1octet_t *di;
  1163. ASN1decoding_t dd0;
  1164. ASN1octet_t *di0;
  1165. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1166. return 0;
  1167. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->secretAdditionalType))
  1168. return 0;
  1169. if (!ASN1BERDecExplicitTag(dd, 0x80000000, &dd0, &di0))
  1170. return 0;
  1171. if (!ASN1BERDecOpenType(dd0, &(val)->secretAdditionalContent))
  1172. return 0;
  1173. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  1174. return 0;
  1175. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1176. return 0;
  1177. return 1;
  1178. }
  1179. static void ASN1CALL ASN1Free_SecretAdditional(SecretAdditional *val)
  1180. {
  1181. if (val) {
  1182. ASN1open_free(&(val)->secretAdditionalContent);
  1183. }
  1184. }
  1185. static int ASN1CALL ASN1Enc_PrivateKeyAlgorithmIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, PrivateKeyAlgorithmIdentifier *val)
  1186. {
  1187. if (!ASN1Enc_AlgorithmIdentifier(enc, tag, val))
  1188. return 0;
  1189. return 1;
  1190. }
  1191. static int ASN1CALL ASN1Dec_PrivateKeyAlgorithmIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, PrivateKeyAlgorithmIdentifier *val)
  1192. {
  1193. if (!ASN1Dec_AlgorithmIdentifier(dec, tag, val))
  1194. return 0;
  1195. return 1;
  1196. }
  1197. static void ASN1CALL ASN1Free_PrivateKeyAlgorithmIdentifier(PrivateKeyAlgorithmIdentifier *val)
  1198. {
  1199. if (val) {
  1200. ASN1Free_AlgorithmIdentifier(val);
  1201. }
  1202. }
  1203. static int ASN1CALL ASN1Enc_EncryptionAlgorithmIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, EncryptionAlgorithmIdentifier *val)
  1204. {
  1205. if (!ASN1Enc_AlgorithmIdentifier(enc, tag, val))
  1206. return 0;
  1207. return 1;
  1208. }
  1209. static int ASN1CALL ASN1Dec_EncryptionAlgorithmIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, EncryptionAlgorithmIdentifier *val)
  1210. {
  1211. if (!ASN1Dec_AlgorithmIdentifier(dec, tag, val))
  1212. return 0;
  1213. return 1;
  1214. }
  1215. static void ASN1CALL ASN1Free_EncryptionAlgorithmIdentifier(EncryptionAlgorithmIdentifier *val)
  1216. {
  1217. if (val) {
  1218. ASN1Free_AlgorithmIdentifier(val);
  1219. }
  1220. }
  1221. static int ASN1CALL ASN1Enc_ContentEncryptionAlgorithmIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, ContentEncryptionAlgorithmIdentifier *val)
  1222. {
  1223. if (!ASN1Enc_AlgorithmIdentifier(enc, tag, val))
  1224. return 0;
  1225. return 1;
  1226. }
  1227. static int ASN1CALL ASN1Dec_ContentEncryptionAlgorithmIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, ContentEncryptionAlgorithmIdentifier *val)
  1228. {
  1229. if (!ASN1Dec_AlgorithmIdentifier(dec, tag, val))
  1230. return 0;
  1231. return 1;
  1232. }
  1233. static void ASN1CALL ASN1Free_ContentEncryptionAlgorithmIdentifier(ContentEncryptionAlgorithmIdentifier *val)
  1234. {
  1235. if (val) {
  1236. ASN1Free_AlgorithmIdentifier(val);
  1237. }
  1238. }
  1239. static int ASN1CALL ASN1Enc_DigestInfo(ASN1encoding_t enc, ASN1uint32_t tag, DigestInfo *val)
  1240. {
  1241. ASN1uint32_t nLenOff;
  1242. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1243. return 0;
  1244. if (!ASN1Enc_DigestAlgorithmIdentifier(enc, 0, &(val)->digestAlgorithm))
  1245. return 0;
  1246. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->digest).length, ((val)->digest).value))
  1247. return 0;
  1248. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1249. return 0;
  1250. return 1;
  1251. }
  1252. static int ASN1CALL ASN1Dec_DigestInfo(ASN1decoding_t dec, ASN1uint32_t tag, DigestInfo *val)
  1253. {
  1254. ASN1decoding_t dd;
  1255. ASN1octet_t *di;
  1256. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1257. return 0;
  1258. if (!ASN1Dec_DigestAlgorithmIdentifier(dd, 0, &(val)->digestAlgorithm))
  1259. return 0;
  1260. if (!ASN1BERDecOctetString(dd, 0x4, &(val)->digest))
  1261. return 0;
  1262. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1263. return 0;
  1264. return 1;
  1265. }
  1266. static void ASN1CALL ASN1Free_DigestInfo(DigestInfo *val)
  1267. {
  1268. if (val) {
  1269. ASN1Free_DigestAlgorithmIdentifier(&(val)->digestAlgorithm);
  1270. ASN1octetstring_free(&(val)->digest);
  1271. }
  1272. }
  1273. static int ASN1CALL ASN1Enc_MacData(ASN1encoding_t enc, ASN1uint32_t tag, MacData *val)
  1274. {
  1275. ASN1uint32_t nLenOff;
  1276. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1277. return 0;
  1278. if (!ASN1Enc_DigestInfo(enc, 0, &(val)->safeMAC))
  1279. return 0;
  1280. if (!ASN1DEREncBitString(enc, 0x3, ((val)->macSalt).length, ((val)->macSalt).value))
  1281. return 0;
  1282. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1283. return 0;
  1284. return 1;
  1285. }
  1286. static int ASN1CALL ASN1Dec_MacData(ASN1decoding_t dec, ASN1uint32_t tag, MacData *val)
  1287. {
  1288. ASN1decoding_t dd;
  1289. ASN1octet_t *di;
  1290. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1291. return 0;
  1292. if (!ASN1Dec_DigestInfo(dd, 0, &(val)->safeMAC))
  1293. return 0;
  1294. if (!ASN1BERDecBitString(dd, 0x3, &(val)->macSalt))
  1295. return 0;
  1296. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1297. return 0;
  1298. return 1;
  1299. }
  1300. static void ASN1CALL ASN1Free_MacData(MacData *val)
  1301. {
  1302. if (val) {
  1303. ASN1Free_DigestInfo(&(val)->safeMAC);
  1304. ASN1bitstring_free(&(val)->macSalt);
  1305. }
  1306. }
  1307. static int ASN1CALL ASN1Enc_AuthenticatedSafe(ASN1encoding_t enc, ASN1uint32_t tag, AuthenticatedSafe *val)
  1308. {
  1309. ASN1uint32_t nLenOff;
  1310. ASN1octet_t o[1];
  1311. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1312. return 0;
  1313. CopyMemory(o, (val)->o, 1);
  1314. if ((val)->version == 1)
  1315. o[0] &= ~0x80;
  1316. if (!ASN1objectidentifier2_cmp(&val->transportMode, &off_lineTransportMode))
  1317. o[0] &= ~0x40;
  1318. if (o[0] & 0x80) {
  1319. if (!ASN1BEREncS32(enc, 0x2, (val)->version))
  1320. return 0;
  1321. }
  1322. if (o[0] & 0x40) {
  1323. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->transportMode))
  1324. return 0;
  1325. }
  1326. if (o[0] & 0x20) {
  1327. if (!ASN1DEREncBitString(enc, 0x3, ((val)->privacySalt).length, ((val)->privacySalt).value))
  1328. return 0;
  1329. }
  1330. if (o[0] & 0x10) {
  1331. if (!ASN1Enc_Baggage(enc, 0, &(val)->baggage))
  1332. return 0;
  1333. }
  1334. if (!ASN1Enc_ContentInfo(enc, 0, &(val)->safe))
  1335. return 0;
  1336. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1337. return 0;
  1338. return 1;
  1339. }
  1340. static int ASN1CALL ASN1Dec_AuthenticatedSafe(ASN1decoding_t dec, ASN1uint32_t tag, AuthenticatedSafe *val)
  1341. {
  1342. ASN1decoding_t dd;
  1343. ASN1octet_t *di;
  1344. ASN1uint32_t t;
  1345. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1346. return 0;
  1347. ZeroMemory((val)->o, 1);
  1348. ASN1BERDecPeekTag(dd, &t);
  1349. if (t == 0x2) {
  1350. (val)->o[0] |= 0x80;
  1351. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->version))
  1352. return 0;
  1353. }
  1354. ASN1BERDecPeekTag(dd, &t);
  1355. if (t == 0x6) {
  1356. (val)->o[0] |= 0x40;
  1357. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->transportMode))
  1358. return 0;
  1359. }
  1360. ASN1BERDecPeekTag(dd, &t);
  1361. if (t == 0x3) {
  1362. (val)->o[0] |= 0x20;
  1363. if (!ASN1BERDecBitString(dd, 0x3, &(val)->privacySalt))
  1364. return 0;
  1365. }
  1366. ASN1BERDecPeekTag(dd, &t);
  1367. if (t == 0x11) {
  1368. (val)->o[0] |= 0x10;
  1369. if (!ASN1Dec_Baggage(dd, 0, &(val)->baggage))
  1370. return 0;
  1371. }
  1372. if (!ASN1Dec_ContentInfo(dd, 0, &(val)->safe))
  1373. return 0;
  1374. if (!((val)->o[0] & 0x80))
  1375. (val)->version = 1;
  1376. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1377. return 0;
  1378. return 1;
  1379. }
  1380. static void ASN1CALL ASN1Free_AuthenticatedSafe(AuthenticatedSafe *val)
  1381. {
  1382. if (val) {
  1383. if ((val)->o[0] & 0x40) {
  1384. }
  1385. if ((val)->o[0] & 0x20) {
  1386. ASN1bitstring_free(&(val)->privacySalt);
  1387. }
  1388. if ((val)->o[0] & 0x10) {
  1389. ASN1Free_Baggage(&(val)->baggage);
  1390. }
  1391. ASN1Free_ContentInfo(&(val)->safe);
  1392. }
  1393. }
  1394. static int ASN1CALL ASN1Enc_Thumbprint(ASN1encoding_t enc, ASN1uint32_t tag, Thumbprint *val)
  1395. {
  1396. if (!ASN1Enc_DigestInfo(enc, tag, val))
  1397. return 0;
  1398. return 1;
  1399. }
  1400. static int ASN1CALL ASN1Dec_Thumbprint(ASN1decoding_t dec, ASN1uint32_t tag, Thumbprint *val)
  1401. {
  1402. if (!ASN1Dec_DigestInfo(dec, tag, val))
  1403. return 0;
  1404. return 1;
  1405. }
  1406. static void ASN1CALL ASN1Free_Thumbprint(Thumbprint *val)
  1407. {
  1408. if (val) {
  1409. ASN1Free_DigestInfo(val);
  1410. }
  1411. }
  1412. static int ASN1CALL ASN1Enc_Secret(ASN1encoding_t enc, ASN1uint32_t tag, Secret *val)
  1413. {
  1414. ASN1uint32_t nLenOff;
  1415. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1416. return 0;
  1417. if (!ASN1DEREncChar16String(enc, 0x1e, ((val)->secretName).length, ((val)->secretName).value))
  1418. return 0;
  1419. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->secretType))
  1420. return 0;
  1421. if (!ASN1BEREncOpenType(enc, &(val)->value))
  1422. return 0;
  1423. if ((val)->o[0] & 0x80) {
  1424. if (!ASN1Enc_SecretAdditional(enc, 0, &(val)->secretAdditional))
  1425. return 0;
  1426. }
  1427. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1428. return 0;
  1429. return 1;
  1430. }
  1431. static int ASN1CALL ASN1Dec_Secret(ASN1decoding_t dec, ASN1uint32_t tag, Secret *val)
  1432. {
  1433. ASN1decoding_t dd;
  1434. ASN1octet_t *di;
  1435. ASN1uint32_t t;
  1436. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1437. return 0;
  1438. ZeroMemory((val)->o, 1);
  1439. if (!ASN1BERDecChar16String(dd, 0x1e, &(val)->secretName))
  1440. return 0;
  1441. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->secretType))
  1442. return 0;
  1443. if (!ASN1BERDecOpenType(dd, &(val)->value))
  1444. return 0;
  1445. ASN1BERDecPeekTag(dd, &t);
  1446. if (t == 0x10) {
  1447. (val)->o[0] |= 0x80;
  1448. if (!ASN1Dec_SecretAdditional(dd, 0, &(val)->secretAdditional))
  1449. return 0;
  1450. }
  1451. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1452. return 0;
  1453. return 1;
  1454. }
  1455. static void ASN1CALL ASN1Free_Secret(Secret *val)
  1456. {
  1457. if (val) {
  1458. ASN1char16string_free(&(val)->secretName);
  1459. ASN1open_free(&(val)->value);
  1460. if ((val)->o[0] & 0x80) {
  1461. ASN1Free_SecretAdditional(&(val)->secretAdditional);
  1462. }
  1463. }
  1464. }
  1465. static int ASN1CALL ASN1Enc_PVKSupportingData_assocCerts(ASN1encoding_t enc, ASN1uint32_t tag, PVKSupportingData_assocCerts *val)
  1466. {
  1467. ASN1uint32_t nLenOff;
  1468. void *pBlk;
  1469. ASN1uint32_t i;
  1470. ASN1encoding_t enc2;
  1471. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  1472. return 0;
  1473. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  1474. return 0;
  1475. for (i = 0; i < (val)->count; i++) {
  1476. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  1477. return 0;
  1478. if (!ASN1Enc_Thumbprint(enc2, 0, &((val)->value)[i]))
  1479. return 0;
  1480. if (!ASN1DEREncFlushBlkElement(pBlk))
  1481. return 0;
  1482. }
  1483. if (!ASN1DEREncEndBlk(pBlk))
  1484. return 0;
  1485. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1486. return 0;
  1487. return 1;
  1488. }
  1489. static int ASN1CALL ASN1Dec_PVKSupportingData_assocCerts(ASN1decoding_t dec, ASN1uint32_t tag, PVKSupportingData_assocCerts *val)
  1490. {
  1491. ASN1decoding_t dd;
  1492. ASN1octet_t *di;
  1493. ASN1uint32_t t;
  1494. ASN1uint32_t n;
  1495. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  1496. return 0;
  1497. (val)->count = n = 0;
  1498. (val)->value = NULL;
  1499. while (ASN1BERDecNotEndOfContents(dd, di)) {
  1500. if (!ASN1BERDecPeekTag(dd, &t))
  1501. return 0;
  1502. if ((val)->count >= n) {
  1503. void *pvASN1DecRealloc;
  1504. n = n ? (n << 1) : 16;
  1505. if (!(pvASN1DecRealloc = ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  1506. return 0;
  1507. (val)->value = (Thumbprint *) pvASN1DecRealloc;
  1508. }
  1509. if (!ASN1Dec_Thumbprint(dd, 0, &((val)->value)[(val)->count]))
  1510. return 0;
  1511. ((val)->count)++;
  1512. }
  1513. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1514. return 0;
  1515. return 1;
  1516. }
  1517. static void ASN1CALL ASN1Free_PVKSupportingData_assocCerts(PVKSupportingData_assocCerts *val)
  1518. {
  1519. ASN1uint32_t i;
  1520. if (val) {
  1521. ASN1Free_Thumbprint(&(val)->value[0]);
  1522. for (i = 1; i < (val)->count; i++) {
  1523. ASN1Free_Thumbprint(&(val)->value[i]);
  1524. }
  1525. ASN1Free((val)->value);
  1526. }
  1527. }
  1528. static int ASN1CALL ASN1Enc_PrivateKeyInfo(ASN1encoding_t enc, ASN1uint32_t tag, PrivateKeyInfo *val)
  1529. {
  1530. ASN1uint32_t nLenOff;
  1531. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1532. return 0;
  1533. if (!ASN1BEREncS32(enc, 0x2, (val)->version))
  1534. return 0;
  1535. if (!ASN1Enc_PrivateKeyAlgorithmIdentifier(enc, 0, &(val)->privateKeyAlgorithm))
  1536. return 0;
  1537. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->privateKey).length, ((val)->privateKey).value))
  1538. return 0;
  1539. if ((val)->o[0] & 0x80) {
  1540. if (!ASN1Enc_Attributes(enc, 0x80000000, &(val)->attributes))
  1541. return 0;
  1542. }
  1543. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1544. return 0;
  1545. return 1;
  1546. }
  1547. static int ASN1CALL ASN1Dec_PrivateKeyInfo(ASN1decoding_t dec, ASN1uint32_t tag, PrivateKeyInfo *val)
  1548. {
  1549. ASN1decoding_t dd;
  1550. ASN1octet_t *di;
  1551. ASN1uint32_t t;
  1552. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1553. return 0;
  1554. ZeroMemory((val)->o, 1);
  1555. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->version))
  1556. return 0;
  1557. if (!ASN1Dec_PrivateKeyAlgorithmIdentifier(dd, 0, &(val)->privateKeyAlgorithm))
  1558. return 0;
  1559. if (!ASN1BERDecOctetString(dd, 0x4, &(val)->privateKey))
  1560. return 0;
  1561. ASN1BERDecPeekTag(dd, &t);
  1562. if (t == 0x80000000) {
  1563. (val)->o[0] |= 0x80;
  1564. if (!ASN1Dec_Attributes(dd, 0x80000000, &(val)->attributes))
  1565. return 0;
  1566. }
  1567. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1568. return 0;
  1569. return 1;
  1570. }
  1571. static void ASN1CALL ASN1Free_PrivateKeyInfo(PrivateKeyInfo *val)
  1572. {
  1573. if (val) {
  1574. ASN1Free_PrivateKeyAlgorithmIdentifier(&(val)->privateKeyAlgorithm);
  1575. ASN1octetstring_free(&(val)->privateKey);
  1576. if ((val)->o[0] & 0x80) {
  1577. ASN1Free_Attributes(&(val)->attributes);
  1578. }
  1579. }
  1580. }
  1581. static int ASN1CALL ASN1Enc_EncryptedContentInfo(ASN1encoding_t enc, ASN1uint32_t tag, EncryptedContentInfo *val)
  1582. {
  1583. ASN1uint32_t nLenOff;
  1584. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1585. return 0;
  1586. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->contentType))
  1587. return 0;
  1588. if (!ASN1Enc_ContentEncryptionAlgorithmIdentifier(enc, 0, &(val)->contentEncryptionAlg))
  1589. return 0;
  1590. if ((val)->o[0] & 0x80) {
  1591. if (!ASN1DEREncOctetString(enc, 0x80000000, ((val)->encryptedContent).length, ((val)->encryptedContent).value))
  1592. return 0;
  1593. }
  1594. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1595. return 0;
  1596. return 1;
  1597. }
  1598. static int ASN1CALL ASN1Dec_EncryptedContentInfo(ASN1decoding_t dec, ASN1uint32_t tag, EncryptedContentInfo *val)
  1599. {
  1600. ASN1decoding_t dd;
  1601. ASN1octet_t *di;
  1602. ASN1uint32_t t;
  1603. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1604. return 0;
  1605. ZeroMemory((val)->o, 1);
  1606. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->contentType))
  1607. return 0;
  1608. if (!ASN1Dec_ContentEncryptionAlgorithmIdentifier(dd, 0, &(val)->contentEncryptionAlg))
  1609. return 0;
  1610. ASN1BERDecPeekTag(dd, &t);
  1611. if (t == 0x80000000) {
  1612. (val)->o[0] |= 0x80;
  1613. if (!ASN1BERDecOctetString(dd, 0x80000000, &(val)->encryptedContent))
  1614. return 0;
  1615. }
  1616. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1617. return 0;
  1618. return 1;
  1619. }
  1620. static void ASN1CALL ASN1Free_EncryptedContentInfo(EncryptedContentInfo *val)
  1621. {
  1622. if (val) {
  1623. ASN1Free_ContentEncryptionAlgorithmIdentifier(&(val)->contentEncryptionAlg);
  1624. if ((val)->o[0] & 0x80) {
  1625. ASN1octetstring_free(&(val)->encryptedContent);
  1626. }
  1627. }
  1628. }
  1629. static int ASN1CALL ASN1Enc_PFX(ASN1encoding_t enc, ASN1uint32_t tag, PFX *val)
  1630. {
  1631. ASN1uint32_t nLenOff;
  1632. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1633. return 0;
  1634. if ((val)->o[0] & 0x80) {
  1635. if (!ASN1Enc_MacData(enc, 0x80000000, &(val)->macData))
  1636. return 0;
  1637. }
  1638. if (!ASN1Enc_ContentInfo(enc, 0x80000001, &(val)->authSafe))
  1639. return 0;
  1640. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1641. return 0;
  1642. return 1;
  1643. }
  1644. static int ASN1CALL ASN1Dec_PFX(ASN1decoding_t dec, ASN1uint32_t tag, PFX *val)
  1645. {
  1646. ASN1decoding_t dd;
  1647. ASN1octet_t *di;
  1648. ASN1uint32_t t;
  1649. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1650. return 0;
  1651. ZeroMemory((val)->o, 1);
  1652. ASN1BERDecPeekTag(dd, &t);
  1653. if (t == 0x80000000) {
  1654. (val)->o[0] |= 0x80;
  1655. if (!ASN1Dec_MacData(dd, 0x80000000, &(val)->macData))
  1656. return 0;
  1657. }
  1658. if (!ASN1Dec_ContentInfo(dd, 0x80000001, &(val)->authSafe))
  1659. return 0;
  1660. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1661. return 0;
  1662. return 1;
  1663. }
  1664. static void ASN1CALL ASN1Free_PFX(PFX *val)
  1665. {
  1666. if (val) {
  1667. if ((val)->o[0] & 0x80) {
  1668. ASN1Free_MacData(&(val)->macData);
  1669. }
  1670. ASN1Free_ContentInfo(&(val)->authSafe);
  1671. }
  1672. }
  1673. static int ASN1CALL ASN1Enc_PVKSupportingData(ASN1encoding_t enc, ASN1uint32_t tag, PVKSupportingData *val)
  1674. {
  1675. ASN1uint32_t nLenOff;
  1676. ASN1octet_t o[1];
  1677. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1678. return 0;
  1679. CopyMemory(o, (val)->o, 1);
  1680. if (!(val)->regenerable)
  1681. o[0] &= ~0x80;
  1682. if (!ASN1Enc_PVKSupportingData_assocCerts(enc, 0, &(val)->assocCerts))
  1683. return 0;
  1684. if (o[0] & 0x80) {
  1685. if (!ASN1BEREncBool(enc, 0x1, (val)->regenerable))
  1686. return 0;
  1687. }
  1688. if (!ASN1DEREncChar16String(enc, 0x1e, ((val)->nickname).length, ((val)->nickname).value))
  1689. return 0;
  1690. if (o[0] & 0x40) {
  1691. if (!ASN1Enc_PvkAdditional(enc, 0, &(val)->pvkAdditional))
  1692. return 0;
  1693. }
  1694. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1695. return 0;
  1696. return 1;
  1697. }
  1698. static int ASN1CALL ASN1Dec_PVKSupportingData(ASN1decoding_t dec, ASN1uint32_t tag, PVKSupportingData *val)
  1699. {
  1700. ASN1decoding_t dd;
  1701. ASN1octet_t *di;
  1702. ASN1uint32_t t;
  1703. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1704. return 0;
  1705. ZeroMemory((val)->o, 1);
  1706. if (!ASN1Dec_PVKSupportingData_assocCerts(dd, 0, &(val)->assocCerts))
  1707. return 0;
  1708. ASN1BERDecPeekTag(dd, &t);
  1709. if (t == 0x1) {
  1710. (val)->o[0] |= 0x80;
  1711. if (!ASN1BERDecBool(dd, 0x1, &(val)->regenerable))
  1712. return 0;
  1713. }
  1714. if (!ASN1BERDecChar16String(dd, 0x1e, &(val)->nickname))
  1715. return 0;
  1716. ASN1BERDecPeekTag(dd, &t);
  1717. if (t == 0x10) {
  1718. (val)->o[0] |= 0x40;
  1719. if (!ASN1Dec_PvkAdditional(dd, 0, &(val)->pvkAdditional))
  1720. return 0;
  1721. }
  1722. if (!((val)->o[0] & 0x80))
  1723. (val)->regenerable = 0;
  1724. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1725. return 0;
  1726. return 1;
  1727. }
  1728. static void ASN1CALL ASN1Free_PVKSupportingData(PVKSupportingData *val)
  1729. {
  1730. if (val) {
  1731. ASN1Free_PVKSupportingData_assocCerts(&(val)->assocCerts);
  1732. ASN1char16string_free(&(val)->nickname);
  1733. if ((val)->o[0] & 0x40) {
  1734. ASN1Free_PvkAdditional(&(val)->pvkAdditional);
  1735. }
  1736. }
  1737. }
  1738. static int ASN1CALL ASN1Enc_PrivateKey(ASN1encoding_t enc, ASN1uint32_t tag, PrivateKey *val)
  1739. {
  1740. ASN1uint32_t nLenOff;
  1741. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1742. return 0;
  1743. if (!ASN1Enc_PVKSupportingData(enc, 0, &(val)->pvkData))
  1744. return 0;
  1745. if (!ASN1Enc_PrivateKeyInfo(enc, 0, &(val)->pkcs8data))
  1746. return 0;
  1747. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1748. return 0;
  1749. return 1;
  1750. }
  1751. static int ASN1CALL ASN1Dec_PrivateKey(ASN1decoding_t dec, ASN1uint32_t tag, PrivateKey *val)
  1752. {
  1753. ASN1decoding_t dd;
  1754. ASN1octet_t *di;
  1755. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1756. return 0;
  1757. if (!ASN1Dec_PVKSupportingData(dd, 0, &(val)->pvkData))
  1758. return 0;
  1759. if (!ASN1Dec_PrivateKeyInfo(dd, 0, &(val)->pkcs8data))
  1760. return 0;
  1761. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1762. return 0;
  1763. return 1;
  1764. }
  1765. static void ASN1CALL ASN1Free_PrivateKey(PrivateKey *val)
  1766. {
  1767. if (val) {
  1768. ASN1Free_PVKSupportingData(&(val)->pvkData);
  1769. ASN1Free_PrivateKeyInfo(&(val)->pkcs8data);
  1770. }
  1771. }
  1772. static int ASN1CALL ASN1Enc_EncryptedData(ASN1encoding_t enc, ASN1uint32_t tag, EncryptedData *val)
  1773. {
  1774. ASN1uint32_t nLenOff;
  1775. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1776. return 0;
  1777. if (!ASN1BEREncS32(enc, 0x2, (val)->version))
  1778. return 0;
  1779. if (!ASN1Enc_EncryptedContentInfo(enc, 0, &(val)->encryptedContentInfo))
  1780. return 0;
  1781. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1782. return 0;
  1783. return 1;
  1784. }
  1785. static int ASN1CALL ASN1Dec_EncryptedData(ASN1decoding_t dec, ASN1uint32_t tag, EncryptedData *val)
  1786. {
  1787. ASN1decoding_t dd;
  1788. ASN1octet_t *di;
  1789. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1790. return 0;
  1791. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->version))
  1792. return 0;
  1793. if (!ASN1Dec_EncryptedContentInfo(dd, 0, &(val)->encryptedContentInfo))
  1794. return 0;
  1795. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1796. return 0;
  1797. return 1;
  1798. }
  1799. static void ASN1CALL ASN1Free_EncryptedData(EncryptedData *val)
  1800. {
  1801. if (val) {
  1802. ASN1Free_EncryptedContentInfo(&(val)->encryptedContentInfo);
  1803. }
  1804. }
  1805. static int ASN1CALL ASN1Enc_ESPVK(ASN1encoding_t enc, ASN1uint32_t tag, ESPVK *val)
  1806. {
  1807. ASN1uint32_t nLenOff;
  1808. ASN1uint32_t nLenOff0;
  1809. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1810. return 0;
  1811. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->espvkObjID))
  1812. return 0;
  1813. if (!ASN1Enc_PVKSupportingData(enc, 0, &(val)->espvkData))
  1814. return 0;
  1815. if (!ASN1BEREncExplicitTag(enc, 0x80000000, &nLenOff0))
  1816. return 0;
  1817. if (!ASN1BEREncOpenType(enc, &(val)->espvkCipherText))
  1818. return 0;
  1819. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  1820. return 0;
  1821. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1822. return 0;
  1823. return 1;
  1824. }
  1825. static int ASN1CALL ASN1Dec_ESPVK(ASN1decoding_t dec, ASN1uint32_t tag, ESPVK *val)
  1826. {
  1827. ASN1decoding_t dd;
  1828. ASN1octet_t *di;
  1829. ASN1decoding_t dd0;
  1830. ASN1octet_t *di0;
  1831. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1832. return 0;
  1833. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->espvkObjID))
  1834. return 0;
  1835. if (!ASN1Dec_PVKSupportingData(dd, 0, &(val)->espvkData))
  1836. return 0;
  1837. if (!ASN1BERDecExplicitTag(dd, 0x80000000, &dd0, &di0))
  1838. return 0;
  1839. if (!ASN1BERDecOpenType(dd0, &(val)->espvkCipherText))
  1840. return 0;
  1841. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  1842. return 0;
  1843. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1844. return 0;
  1845. return 1;
  1846. }
  1847. static void ASN1CALL ASN1Free_ESPVK(ESPVK *val)
  1848. {
  1849. if (val) {
  1850. ASN1Free_PVKSupportingData(&(val)->espvkData);
  1851. ASN1open_free(&(val)->espvkCipherText);
  1852. }
  1853. }
  1854. static int ASN1CALL ASN1Enc_EncryptedPrivateKeyInfo(ASN1encoding_t enc, ASN1uint32_t tag, EncryptedPrivateKeyInfo *val)
  1855. {
  1856. ASN1uint32_t nLenOff;
  1857. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1858. return 0;
  1859. if (!ASN1Enc_EncryptionAlgorithmIdentifier(enc, 0, &(val)->encryptionAlgorithm))
  1860. return 0;
  1861. if (!ASN1Enc_EncryptedData(enc, 0, &(val)->encryptedData))
  1862. return 0;
  1863. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1864. return 0;
  1865. return 1;
  1866. }
  1867. static int ASN1CALL ASN1Dec_EncryptedPrivateKeyInfo(ASN1decoding_t dec, ASN1uint32_t tag, EncryptedPrivateKeyInfo *val)
  1868. {
  1869. ASN1decoding_t dd;
  1870. ASN1octet_t *di;
  1871. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1872. return 0;
  1873. if (!ASN1Dec_EncryptionAlgorithmIdentifier(dd, 0, &(val)->encryptionAlgorithm))
  1874. return 0;
  1875. if (!ASN1Dec_EncryptedData(dd, 0, &(val)->encryptedData))
  1876. return 0;
  1877. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1878. return 0;
  1879. return 1;
  1880. }
  1881. static void ASN1CALL ASN1Free_EncryptedPrivateKeyInfo(EncryptedPrivateKeyInfo *val)
  1882. {
  1883. if (val) {
  1884. ASN1Free_EncryptionAlgorithmIdentifier(&(val)->encryptionAlgorithm);
  1885. ASN1Free_EncryptedData(&(val)->encryptedData);
  1886. }
  1887. }