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.

487 lines
16 KiB

  1. /* Copyright (C) Microsoft Corporation, 1996 - 1999 All rights reserved. */
  2. /* ASN.1 definitions for X509 v3 certificates */
  3. #include <windows.h>
  4. #include "prvtkey.h"
  5. ASN1module_t PRVTKEY_Module = NULL;
  6. static int ASN1CALL ASN1Enc_AlgorithmIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, AlgorithmIdentifier *val);
  7. static int ASN1CALL ASN1Enc_AttributeSetValue(ASN1encoding_t enc, ASN1uint32_t tag, AttributeSetValue *val);
  8. static int ASN1CALL ASN1Enc_Attributes(ASN1encoding_t enc, ASN1uint32_t tag, Attributes *val);
  9. static int ASN1CALL ASN1Enc_RSAPrivateKey(ASN1encoding_t enc, ASN1uint32_t tag, RSAPrivateKey *val);
  10. static int ASN1CALL ASN1Enc_PrivateKeyAlgorithmIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, PrivateKeyAlgorithmIdentifier *val);
  11. static int ASN1CALL ASN1Enc_PrivateKeyInfo(ASN1encoding_t enc, ASN1uint32_t tag, PrivateKeyInfo *val);
  12. static int ASN1CALL ASN1Enc_EncryptionAlgorithmIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, EncryptionAlgorithmIdentifier *val);
  13. static int ASN1CALL ASN1Enc_EncryptedPrivateKeyInfo(ASN1encoding_t enc, ASN1uint32_t tag, EncryptedPrivateKeyInfo *val);
  14. static int ASN1CALL ASN1Enc_Attribute(ASN1encoding_t enc, ASN1uint32_t tag, Attribute *val);
  15. static int ASN1CALL ASN1Dec_AlgorithmIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, AlgorithmIdentifier *val);
  16. static int ASN1CALL ASN1Dec_AttributeSetValue(ASN1decoding_t dec, ASN1uint32_t tag, AttributeSetValue *val);
  17. static int ASN1CALL ASN1Dec_Attributes(ASN1decoding_t dec, ASN1uint32_t tag, Attributes *val);
  18. static int ASN1CALL ASN1Dec_RSAPrivateKey(ASN1decoding_t dec, ASN1uint32_t tag, RSAPrivateKey *val);
  19. static int ASN1CALL ASN1Dec_PrivateKeyAlgorithmIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, PrivateKeyAlgorithmIdentifier *val);
  20. static int ASN1CALL ASN1Dec_PrivateKeyInfo(ASN1decoding_t dec, ASN1uint32_t tag, PrivateKeyInfo *val);
  21. static int ASN1CALL ASN1Dec_EncryptionAlgorithmIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, EncryptionAlgorithmIdentifier *val);
  22. static int ASN1CALL ASN1Dec_EncryptedPrivateKeyInfo(ASN1decoding_t dec, ASN1uint32_t tag, EncryptedPrivateKeyInfo *val);
  23. static int ASN1CALL ASN1Dec_Attribute(ASN1decoding_t dec, ASN1uint32_t tag, Attribute *val);
  24. static void ASN1CALL ASN1Free_AlgorithmIdentifier(AlgorithmIdentifier *val);
  25. static void ASN1CALL ASN1Free_AttributeSetValue(AttributeSetValue *val);
  26. static void ASN1CALL ASN1Free_Attributes(Attributes *val);
  27. static void ASN1CALL ASN1Free_RSAPrivateKey(RSAPrivateKey *val);
  28. static void ASN1CALL ASN1Free_PrivateKeyAlgorithmIdentifier(PrivateKeyAlgorithmIdentifier *val);
  29. static void ASN1CALL ASN1Free_PrivateKeyInfo(PrivateKeyInfo *val);
  30. static void ASN1CALL ASN1Free_EncryptionAlgorithmIdentifier(EncryptionAlgorithmIdentifier *val);
  31. static void ASN1CALL ASN1Free_EncryptedPrivateKeyInfo(EncryptedPrivateKeyInfo *val);
  32. static void ASN1CALL ASN1Free_Attribute(Attribute *val);
  33. typedef ASN1BerEncFun_t ASN1EncFun_t;
  34. static const ASN1EncFun_t encfntab[4] = {
  35. (ASN1EncFun_t) ASN1Enc_RSAPrivateKey,
  36. (ASN1EncFun_t) ASN1Enc_PrivateKeyInfo,
  37. (ASN1EncFun_t) ASN1Enc_EncryptedPrivateKeyInfo,
  38. (ASN1EncFun_t) ASN1Enc_Attribute,
  39. };
  40. typedef ASN1BerDecFun_t ASN1DecFun_t;
  41. static const ASN1DecFun_t decfntab[4] = {
  42. (ASN1DecFun_t) ASN1Dec_RSAPrivateKey,
  43. (ASN1DecFun_t) ASN1Dec_PrivateKeyInfo,
  44. (ASN1DecFun_t) ASN1Dec_EncryptedPrivateKeyInfo,
  45. (ASN1DecFun_t) ASN1Dec_Attribute,
  46. };
  47. static const ASN1FreeFun_t freefntab[4] = {
  48. (ASN1FreeFun_t) ASN1Free_RSAPrivateKey,
  49. (ASN1FreeFun_t) ASN1Free_PrivateKeyInfo,
  50. (ASN1FreeFun_t) ASN1Free_EncryptedPrivateKeyInfo,
  51. (ASN1FreeFun_t) ASN1Free_Attribute,
  52. };
  53. static const ULONG sizetab[4] = {
  54. SIZE_PRVTKEY_Module_PDU_0,
  55. SIZE_PRVTKEY_Module_PDU_1,
  56. SIZE_PRVTKEY_Module_PDU_2,
  57. SIZE_PRVTKEY_Module_PDU_3,
  58. };
  59. /* forward declarations of values: */
  60. /* definitions of value components: */
  61. /* definitions of values: */
  62. void ASN1CALL PRVTKEY_Module_Startup(void)
  63. {
  64. PRVTKEY_Module = ASN1_CreateModule(0x10000, ASN1_BER_RULE_DER, ASN1FLAGS_NOASSERT, 4, (const ASN1GenericFun_t *) encfntab, (const ASN1GenericFun_t *) decfntab, freefntab, sizetab, 0x74767270);
  65. }
  66. void ASN1CALL PRVTKEY_Module_Cleanup(void)
  67. {
  68. ASN1_CloseModule(PRVTKEY_Module);
  69. PRVTKEY_Module = NULL;
  70. }
  71. static int ASN1CALL ASN1Enc_AlgorithmIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, AlgorithmIdentifier *val)
  72. {
  73. ASN1uint32_t nLenOff;
  74. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  75. return 0;
  76. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->algorithm))
  77. return 0;
  78. if ((val)->o[0] & 0x80) {
  79. if (!ASN1BEREncOpenType(enc, &(val)->parameters))
  80. return 0;
  81. }
  82. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  83. return 0;
  84. return 1;
  85. }
  86. static int ASN1CALL ASN1Dec_AlgorithmIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, AlgorithmIdentifier *val)
  87. {
  88. ASN1decoding_t dd;
  89. ASN1octet_t *di;
  90. ASN1uint32_t t;
  91. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  92. return 0;
  93. ZeroMemory((val)->o, 1);
  94. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->algorithm))
  95. return 0;
  96. if (ASN1BERDecPeekTag(dd, &t)) {
  97. (val)->o[0] |= 0x80;
  98. if (!ASN1BERDecOpenType2(dd, &(val)->parameters))
  99. return 0;
  100. }
  101. if (!ASN1BERDecEndOfContents(dec, dd, di))
  102. return 0;
  103. return 1;
  104. }
  105. static void ASN1CALL ASN1Free_AlgorithmIdentifier(AlgorithmIdentifier *val)
  106. {
  107. if (val) {
  108. if ((val)->o[0] & 0x80) {
  109. }
  110. }
  111. }
  112. static int ASN1CALL ASN1Enc_AttributeSetValue(ASN1encoding_t enc, ASN1uint32_t tag, AttributeSetValue *val)
  113. {
  114. ASN1uint32_t nLenOff;
  115. void *pBlk;
  116. ASN1uint32_t i;
  117. ASN1encoding_t enc2;
  118. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  119. return 0;
  120. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  121. return 0;
  122. for (i = 0; i < (val)->count; i++) {
  123. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  124. return 0;
  125. if (!ASN1BEREncOpenType(enc2, &((val)->value)[i]))
  126. return 0;
  127. if (!ASN1DEREncFlushBlkElement(pBlk))
  128. return 0;
  129. }
  130. if (!ASN1DEREncEndBlk(pBlk))
  131. return 0;
  132. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  133. return 0;
  134. return 1;
  135. }
  136. static int ASN1CALL ASN1Dec_AttributeSetValue(ASN1decoding_t dec, ASN1uint32_t tag, AttributeSetValue *val)
  137. {
  138. ASN1decoding_t dd;
  139. ASN1octet_t *di;
  140. ASN1uint32_t t;
  141. ASN1uint32_t n;
  142. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  143. return 0;
  144. (val)->count = n = 0;
  145. (val)->value = NULL;
  146. while (ASN1BERDecNotEndOfContents(dd, di)) {
  147. if (!ASN1BERDecPeekTag(dd, &t))
  148. return 0;
  149. if ((val)->count >= n) {
  150. n = n ? (n << 1) : 16;
  151. if (!((val)->value = (NOCOPYANY *)ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  152. return 0;
  153. }
  154. if (!ASN1BERDecOpenType2(dd, &((val)->value)[(val)->count]))
  155. return 0;
  156. ((val)->count)++;
  157. }
  158. if (!ASN1BERDecEndOfContents(dec, dd, di))
  159. return 0;
  160. return 1;
  161. }
  162. static void ASN1CALL ASN1Free_AttributeSetValue(AttributeSetValue *val)
  163. {
  164. ASN1uint32_t i;
  165. if (val) {
  166. for (i = 1; i < (val)->count; i++) {
  167. }
  168. ASN1Free((val)->value);
  169. }
  170. }
  171. static int ASN1CALL ASN1Enc_Attributes(ASN1encoding_t enc, ASN1uint32_t tag, Attributes *val)
  172. {
  173. ASN1uint32_t nLenOff;
  174. void *pBlk;
  175. ASN1uint32_t i;
  176. ASN1encoding_t enc2;
  177. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  178. return 0;
  179. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  180. return 0;
  181. for (i = 0; i < (val)->count; i++) {
  182. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  183. return 0;
  184. if (!ASN1Enc_Attribute(enc2, 0, &((val)->value)[i]))
  185. return 0;
  186. if (!ASN1DEREncFlushBlkElement(pBlk))
  187. return 0;
  188. }
  189. if (!ASN1DEREncEndBlk(pBlk))
  190. return 0;
  191. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  192. return 0;
  193. return 1;
  194. }
  195. static int ASN1CALL ASN1Dec_Attributes(ASN1decoding_t dec, ASN1uint32_t tag, Attributes *val)
  196. {
  197. ASN1decoding_t dd;
  198. ASN1octet_t *di;
  199. ASN1uint32_t t;
  200. ASN1uint32_t n;
  201. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  202. return 0;
  203. (val)->count = n = 0;
  204. (val)->value = NULL;
  205. while (ASN1BERDecNotEndOfContents(dd, di)) {
  206. if (!ASN1BERDecPeekTag(dd, &t))
  207. return 0;
  208. if ((val)->count >= n) {
  209. n = n ? (n << 1) : 16;
  210. if (!((val)->value = (Attribute *)ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  211. return 0;
  212. }
  213. if (!ASN1Dec_Attribute(dd, 0, &((val)->value)[(val)->count]))
  214. return 0;
  215. ((val)->count)++;
  216. }
  217. if (!ASN1BERDecEndOfContents(dec, dd, di))
  218. return 0;
  219. return 1;
  220. }
  221. static void ASN1CALL ASN1Free_Attributes(Attributes *val)
  222. {
  223. ASN1uint32_t i;
  224. if (val) {
  225. ASN1Free_Attribute(&(val)->value[0]);
  226. for (i = 1; i < (val)->count; i++) {
  227. ASN1Free_Attribute(&(val)->value[i]);
  228. }
  229. ASN1Free((val)->value);
  230. }
  231. }
  232. static int ASN1CALL ASN1Enc_RSAPrivateKey(ASN1encoding_t enc, ASN1uint32_t tag, RSAPrivateKey *val)
  233. {
  234. ASN1uint32_t nLenOff;
  235. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  236. return 0;
  237. if (!ASN1BEREncS32(enc, 0x2, (val)->version))
  238. return 0;
  239. if (!ASN1BEREncSX(enc, 0x2, &(val)->modulus))
  240. return 0;
  241. if (!ASN1BEREncS32(enc, 0x2, (val)->publicExponent))
  242. return 0;
  243. if (!ASN1BEREncSX(enc, 0x2, &(val)->privateExponent))
  244. return 0;
  245. if (!ASN1BEREncSX(enc, 0x2, &(val)->prime1))
  246. return 0;
  247. if (!ASN1BEREncSX(enc, 0x2, &(val)->prime2))
  248. return 0;
  249. if (!ASN1BEREncSX(enc, 0x2, &(val)->exponent1))
  250. return 0;
  251. if (!ASN1BEREncSX(enc, 0x2, &(val)->exponent2))
  252. return 0;
  253. if (!ASN1BEREncSX(enc, 0x2, &(val)->coefficient))
  254. return 0;
  255. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  256. return 0;
  257. return 1;
  258. }
  259. static int ASN1CALL ASN1Dec_RSAPrivateKey(ASN1decoding_t dec, ASN1uint32_t tag, RSAPrivateKey *val)
  260. {
  261. ASN1decoding_t dd;
  262. ASN1octet_t *di;
  263. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  264. return 0;
  265. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->version))
  266. return 0;
  267. if (!ASN1BERDecSXVal(dd, 0x2, &(val)->modulus))
  268. return 0;
  269. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->publicExponent))
  270. return 0;
  271. if (!ASN1BERDecSXVal(dd, 0x2, &(val)->privateExponent))
  272. return 0;
  273. if (!ASN1BERDecSXVal(dd, 0x2, &(val)->prime1))
  274. return 0;
  275. if (!ASN1BERDecSXVal(dd, 0x2, &(val)->prime2))
  276. return 0;
  277. if (!ASN1BERDecSXVal(dd, 0x2, &(val)->exponent1))
  278. return 0;
  279. if (!ASN1BERDecSXVal(dd, 0x2, &(val)->exponent2))
  280. return 0;
  281. if (!ASN1BERDecSXVal(dd, 0x2, &(val)->coefficient))
  282. return 0;
  283. if (!ASN1BERDecEndOfContents(dec, dd, di))
  284. return 0;
  285. return 1;
  286. }
  287. static void ASN1CALL ASN1Free_RSAPrivateKey(RSAPrivateKey *val)
  288. {
  289. if (val) {
  290. ASN1intx_free(&(val)->modulus);
  291. ASN1intx_free(&(val)->privateExponent);
  292. ASN1intx_free(&(val)->prime1);
  293. ASN1intx_free(&(val)->prime2);
  294. ASN1intx_free(&(val)->exponent1);
  295. ASN1intx_free(&(val)->exponent2);
  296. ASN1intx_free(&(val)->coefficient);
  297. }
  298. }
  299. static int ASN1CALL ASN1Enc_PrivateKeyAlgorithmIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, PrivateKeyAlgorithmIdentifier *val)
  300. {
  301. if (!ASN1Enc_AlgorithmIdentifier(enc, tag, val))
  302. return 0;
  303. return 1;
  304. }
  305. static int ASN1CALL ASN1Dec_PrivateKeyAlgorithmIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, PrivateKeyAlgorithmIdentifier *val)
  306. {
  307. if (!ASN1Dec_AlgorithmIdentifier(dec, tag, val))
  308. return 0;
  309. return 1;
  310. }
  311. static void ASN1CALL ASN1Free_PrivateKeyAlgorithmIdentifier(PrivateKeyAlgorithmIdentifier *val)
  312. {
  313. if (val) {
  314. ASN1Free_AlgorithmIdentifier(val);
  315. }
  316. }
  317. static int ASN1CALL ASN1Enc_PrivateKeyInfo(ASN1encoding_t enc, ASN1uint32_t tag, PrivateKeyInfo *val)
  318. {
  319. ASN1uint32_t nLenOff;
  320. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  321. return 0;
  322. if (!ASN1BEREncS32(enc, 0x2, (val)->version))
  323. return 0;
  324. if (!ASN1Enc_PrivateKeyAlgorithmIdentifier(enc, 0, &(val)->privateKeyAlgorithm))
  325. return 0;
  326. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->privateKey).length, ((val)->privateKey).value))
  327. return 0;
  328. if ((val)->o[0] & 0x80) {
  329. if (!ASN1Enc_Attributes(enc, 0x80000000, &(val)->privateKeyAttributes))
  330. return 0;
  331. }
  332. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  333. return 0;
  334. return 1;
  335. }
  336. static int ASN1CALL ASN1Dec_PrivateKeyInfo(ASN1decoding_t dec, ASN1uint32_t tag, PrivateKeyInfo *val)
  337. {
  338. ASN1decoding_t dd;
  339. ASN1octet_t *di;
  340. ASN1uint32_t t;
  341. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  342. return 0;
  343. ZeroMemory((val)->o, 1);
  344. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->version))
  345. return 0;
  346. if (!ASN1Dec_PrivateKeyAlgorithmIdentifier(dd, 0, &(val)->privateKeyAlgorithm))
  347. return 0;
  348. if (!ASN1BERDecOctetString2(dd, 0x4, &(val)->privateKey))
  349. return 0;
  350. ASN1BERDecPeekTag(dd, &t);
  351. if (t == 0x80000000) {
  352. (val)->o[0] |= 0x80;
  353. if (!ASN1Dec_Attributes(dd, 0x80000000, &(val)->privateKeyAttributes))
  354. return 0;
  355. }
  356. if (!ASN1BERDecEndOfContents(dec, dd, di))
  357. return 0;
  358. return 1;
  359. }
  360. static void ASN1CALL ASN1Free_PrivateKeyInfo(PrivateKeyInfo *val)
  361. {
  362. if (val) {
  363. ASN1Free_PrivateKeyAlgorithmIdentifier(&(val)->privateKeyAlgorithm);
  364. if ((val)->o[0] & 0x80) {
  365. ASN1Free_Attributes(&(val)->privateKeyAttributes);
  366. }
  367. }
  368. }
  369. static int ASN1CALL ASN1Enc_EncryptionAlgorithmIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, EncryptionAlgorithmIdentifier *val)
  370. {
  371. if (!ASN1Enc_AlgorithmIdentifier(enc, tag, val))
  372. return 0;
  373. return 1;
  374. }
  375. static int ASN1CALL ASN1Dec_EncryptionAlgorithmIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, EncryptionAlgorithmIdentifier *val)
  376. {
  377. if (!ASN1Dec_AlgorithmIdentifier(dec, tag, val))
  378. return 0;
  379. return 1;
  380. }
  381. static void ASN1CALL ASN1Free_EncryptionAlgorithmIdentifier(EncryptionAlgorithmIdentifier *val)
  382. {
  383. if (val) {
  384. ASN1Free_AlgorithmIdentifier(val);
  385. }
  386. }
  387. static int ASN1CALL ASN1Enc_EncryptedPrivateKeyInfo(ASN1encoding_t enc, ASN1uint32_t tag, EncryptedPrivateKeyInfo *val)
  388. {
  389. ASN1uint32_t nLenOff;
  390. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  391. return 0;
  392. if (!ASN1Enc_EncryptionAlgorithmIdentifier(enc, 0, &(val)->encryptionAlgorithm))
  393. return 0;
  394. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->encryptedData).length, ((val)->encryptedData).value))
  395. return 0;
  396. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  397. return 0;
  398. return 1;
  399. }
  400. static int ASN1CALL ASN1Dec_EncryptedPrivateKeyInfo(ASN1decoding_t dec, ASN1uint32_t tag, EncryptedPrivateKeyInfo *val)
  401. {
  402. ASN1decoding_t dd;
  403. ASN1octet_t *di;
  404. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  405. return 0;
  406. if (!ASN1Dec_EncryptionAlgorithmIdentifier(dd, 0, &(val)->encryptionAlgorithm))
  407. return 0;
  408. if (!ASN1BERDecOctetString2(dd, 0x4, &(val)->encryptedData))
  409. return 0;
  410. if (!ASN1BERDecEndOfContents(dec, dd, di))
  411. return 0;
  412. return 1;
  413. }
  414. static void ASN1CALL ASN1Free_EncryptedPrivateKeyInfo(EncryptedPrivateKeyInfo *val)
  415. {
  416. if (val) {
  417. ASN1Free_EncryptionAlgorithmIdentifier(&(val)->encryptionAlgorithm);
  418. }
  419. }
  420. static int ASN1CALL ASN1Enc_Attribute(ASN1encoding_t enc, ASN1uint32_t tag, Attribute *val)
  421. {
  422. ASN1uint32_t nLenOff;
  423. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  424. return 0;
  425. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->type))
  426. return 0;
  427. if (!ASN1Enc_AttributeSetValue(enc, 0, &(val)->values))
  428. return 0;
  429. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  430. return 0;
  431. return 1;
  432. }
  433. static int ASN1CALL ASN1Dec_Attribute(ASN1decoding_t dec, ASN1uint32_t tag, Attribute *val)
  434. {
  435. ASN1decoding_t dd;
  436. ASN1octet_t *di;
  437. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  438. return 0;
  439. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->type))
  440. return 0;
  441. if (!ASN1Dec_AttributeSetValue(dd, 0, &(val)->values))
  442. return 0;
  443. if (!ASN1BERDecEndOfContents(dec, dd, di))
  444. return 0;
  445. return 1;
  446. }
  447. static void ASN1CALL ASN1Free_Attribute(Attribute *val)
  448. {
  449. if (val) {
  450. ASN1Free_AttributeSetValue(&(val)->values);
  451. }
  452. }