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

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