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.

491 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. void *pvASN1DecRealloc;
  151. n = n ? (n << 1) : 16;
  152. if (!(pvASN1DecRealloc = ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  153. return 0;
  154. (val)->value = (NOCOPYANY *) pvASN1DecRealloc;
  155. }
  156. if (!ASN1BERDecOpenType2(dd, &((val)->value)[(val)->count]))
  157. return 0;
  158. ((val)->count)++;
  159. }
  160. if (!ASN1BERDecEndOfContents(dec, dd, di))
  161. return 0;
  162. return 1;
  163. }
  164. static void ASN1CALL ASN1Free_AttributeSetValue(AttributeSetValue *val)
  165. {
  166. ASN1uint32_t i;
  167. if (val) {
  168. for (i = 1; i < (val)->count; i++) {
  169. }
  170. ASN1Free((val)->value);
  171. }
  172. }
  173. static int ASN1CALL ASN1Enc_Attributes(ASN1encoding_t enc, ASN1uint32_t tag, Attributes *val)
  174. {
  175. ASN1uint32_t nLenOff;
  176. void *pBlk;
  177. ASN1uint32_t i;
  178. ASN1encoding_t enc2;
  179. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  180. return 0;
  181. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  182. return 0;
  183. for (i = 0; i < (val)->count; i++) {
  184. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  185. return 0;
  186. if (!ASN1Enc_Attribute(enc2, 0, &((val)->value)[i]))
  187. return 0;
  188. if (!ASN1DEREncFlushBlkElement(pBlk))
  189. return 0;
  190. }
  191. if (!ASN1DEREncEndBlk(pBlk))
  192. return 0;
  193. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  194. return 0;
  195. return 1;
  196. }
  197. static int ASN1CALL ASN1Dec_Attributes(ASN1decoding_t dec, ASN1uint32_t tag, Attributes *val)
  198. {
  199. ASN1decoding_t dd;
  200. ASN1octet_t *di;
  201. ASN1uint32_t t;
  202. ASN1uint32_t n;
  203. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  204. return 0;
  205. (val)->count = n = 0;
  206. (val)->value = NULL;
  207. while (ASN1BERDecNotEndOfContents(dd, di)) {
  208. if (!ASN1BERDecPeekTag(dd, &t))
  209. return 0;
  210. if ((val)->count >= n) {
  211. void *pvASN1DecRealloc;
  212. n = n ? (n << 1) : 16;
  213. if (!(pvASN1DecRealloc = ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  214. return 0;
  215. (val)->value = (Attribute *) pvASN1DecRealloc;
  216. }
  217. if (!ASN1Dec_Attribute(dd, 0, &((val)->value)[(val)->count]))
  218. return 0;
  219. ((val)->count)++;
  220. }
  221. if (!ASN1BERDecEndOfContents(dec, dd, di))
  222. return 0;
  223. return 1;
  224. }
  225. static void ASN1CALL ASN1Free_Attributes(Attributes *val)
  226. {
  227. ASN1uint32_t i;
  228. if (val) {
  229. ASN1Free_Attribute(&(val)->value[0]);
  230. for (i = 1; i < (val)->count; i++) {
  231. ASN1Free_Attribute(&(val)->value[i]);
  232. }
  233. ASN1Free((val)->value);
  234. }
  235. }
  236. static int ASN1CALL ASN1Enc_RSAPrivateKey(ASN1encoding_t enc, ASN1uint32_t tag, RSAPrivateKey *val)
  237. {
  238. ASN1uint32_t nLenOff;
  239. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  240. return 0;
  241. if (!ASN1BEREncS32(enc, 0x2, (val)->version))
  242. return 0;
  243. if (!ASN1BEREncSX(enc, 0x2, &(val)->modulus))
  244. return 0;
  245. if (!ASN1BEREncS32(enc, 0x2, (val)->publicExponent))
  246. return 0;
  247. if (!ASN1BEREncSX(enc, 0x2, &(val)->privateExponent))
  248. return 0;
  249. if (!ASN1BEREncSX(enc, 0x2, &(val)->prime1))
  250. return 0;
  251. if (!ASN1BEREncSX(enc, 0x2, &(val)->prime2))
  252. return 0;
  253. if (!ASN1BEREncSX(enc, 0x2, &(val)->exponent1))
  254. return 0;
  255. if (!ASN1BEREncSX(enc, 0x2, &(val)->exponent2))
  256. return 0;
  257. if (!ASN1BEREncSX(enc, 0x2, &(val)->coefficient))
  258. return 0;
  259. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  260. return 0;
  261. return 1;
  262. }
  263. static int ASN1CALL ASN1Dec_RSAPrivateKey(ASN1decoding_t dec, ASN1uint32_t tag, RSAPrivateKey *val)
  264. {
  265. ASN1decoding_t dd;
  266. ASN1octet_t *di;
  267. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  268. return 0;
  269. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->version))
  270. return 0;
  271. if (!ASN1BERDecSXVal(dd, 0x2, &(val)->modulus))
  272. return 0;
  273. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->publicExponent))
  274. return 0;
  275. if (!ASN1BERDecSXVal(dd, 0x2, &(val)->privateExponent))
  276. return 0;
  277. if (!ASN1BERDecSXVal(dd, 0x2, &(val)->prime1))
  278. return 0;
  279. if (!ASN1BERDecSXVal(dd, 0x2, &(val)->prime2))
  280. return 0;
  281. if (!ASN1BERDecSXVal(dd, 0x2, &(val)->exponent1))
  282. return 0;
  283. if (!ASN1BERDecSXVal(dd, 0x2, &(val)->exponent2))
  284. return 0;
  285. if (!ASN1BERDecSXVal(dd, 0x2, &(val)->coefficient))
  286. return 0;
  287. if (!ASN1BERDecEndOfContents(dec, dd, di))
  288. return 0;
  289. return 1;
  290. }
  291. static void ASN1CALL ASN1Free_RSAPrivateKey(RSAPrivateKey *val)
  292. {
  293. if (val) {
  294. ASN1intx_free(&(val)->modulus);
  295. ASN1intx_free(&(val)->privateExponent);
  296. ASN1intx_free(&(val)->prime1);
  297. ASN1intx_free(&(val)->prime2);
  298. ASN1intx_free(&(val)->exponent1);
  299. ASN1intx_free(&(val)->exponent2);
  300. ASN1intx_free(&(val)->coefficient);
  301. }
  302. }
  303. static int ASN1CALL ASN1Enc_PrivateKeyAlgorithmIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, PrivateKeyAlgorithmIdentifier *val)
  304. {
  305. if (!ASN1Enc_AlgorithmIdentifier(enc, tag, val))
  306. return 0;
  307. return 1;
  308. }
  309. static int ASN1CALL ASN1Dec_PrivateKeyAlgorithmIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, PrivateKeyAlgorithmIdentifier *val)
  310. {
  311. if (!ASN1Dec_AlgorithmIdentifier(dec, tag, val))
  312. return 0;
  313. return 1;
  314. }
  315. static void ASN1CALL ASN1Free_PrivateKeyAlgorithmIdentifier(PrivateKeyAlgorithmIdentifier *val)
  316. {
  317. if (val) {
  318. ASN1Free_AlgorithmIdentifier(val);
  319. }
  320. }
  321. static int ASN1CALL ASN1Enc_PrivateKeyInfo(ASN1encoding_t enc, ASN1uint32_t tag, PrivateKeyInfo *val)
  322. {
  323. ASN1uint32_t nLenOff;
  324. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  325. return 0;
  326. if (!ASN1BEREncS32(enc, 0x2, (val)->version))
  327. return 0;
  328. if (!ASN1Enc_PrivateKeyAlgorithmIdentifier(enc, 0, &(val)->privateKeyAlgorithm))
  329. return 0;
  330. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->privateKey).length, ((val)->privateKey).value))
  331. return 0;
  332. if ((val)->o[0] & 0x80) {
  333. if (!ASN1Enc_Attributes(enc, 0x80000000, &(val)->privateKeyAttributes))
  334. return 0;
  335. }
  336. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  337. return 0;
  338. return 1;
  339. }
  340. static int ASN1CALL ASN1Dec_PrivateKeyInfo(ASN1decoding_t dec, ASN1uint32_t tag, PrivateKeyInfo *val)
  341. {
  342. ASN1decoding_t dd;
  343. ASN1octet_t *di;
  344. ASN1uint32_t t;
  345. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  346. return 0;
  347. ZeroMemory((val)->o, 1);
  348. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->version))
  349. return 0;
  350. if (!ASN1Dec_PrivateKeyAlgorithmIdentifier(dd, 0, &(val)->privateKeyAlgorithm))
  351. return 0;
  352. if (!ASN1BERDecOctetString2(dd, 0x4, &(val)->privateKey))
  353. return 0;
  354. ASN1BERDecPeekTag(dd, &t);
  355. if (t == 0x80000000) {
  356. (val)->o[0] |= 0x80;
  357. if (!ASN1Dec_Attributes(dd, 0x80000000, &(val)->privateKeyAttributes))
  358. return 0;
  359. }
  360. if (!ASN1BERDecEndOfContents(dec, dd, di))
  361. return 0;
  362. return 1;
  363. }
  364. static void ASN1CALL ASN1Free_PrivateKeyInfo(PrivateKeyInfo *val)
  365. {
  366. if (val) {
  367. ASN1Free_PrivateKeyAlgorithmIdentifier(&(val)->privateKeyAlgorithm);
  368. if ((val)->o[0] & 0x80) {
  369. ASN1Free_Attributes(&(val)->privateKeyAttributes);
  370. }
  371. }
  372. }
  373. static int ASN1CALL ASN1Enc_EncryptionAlgorithmIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, EncryptionAlgorithmIdentifier *val)
  374. {
  375. if (!ASN1Enc_AlgorithmIdentifier(enc, tag, val))
  376. return 0;
  377. return 1;
  378. }
  379. static int ASN1CALL ASN1Dec_EncryptionAlgorithmIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, EncryptionAlgorithmIdentifier *val)
  380. {
  381. if (!ASN1Dec_AlgorithmIdentifier(dec, tag, val))
  382. return 0;
  383. return 1;
  384. }
  385. static void ASN1CALL ASN1Free_EncryptionAlgorithmIdentifier(EncryptionAlgorithmIdentifier *val)
  386. {
  387. if (val) {
  388. ASN1Free_AlgorithmIdentifier(val);
  389. }
  390. }
  391. static int ASN1CALL ASN1Enc_EncryptedPrivateKeyInfo(ASN1encoding_t enc, ASN1uint32_t tag, EncryptedPrivateKeyInfo *val)
  392. {
  393. ASN1uint32_t nLenOff;
  394. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  395. return 0;
  396. if (!ASN1Enc_EncryptionAlgorithmIdentifier(enc, 0, &(val)->encryptionAlgorithm))
  397. return 0;
  398. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->encryptedData).length, ((val)->encryptedData).value))
  399. return 0;
  400. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  401. return 0;
  402. return 1;
  403. }
  404. static int ASN1CALL ASN1Dec_EncryptedPrivateKeyInfo(ASN1decoding_t dec, ASN1uint32_t tag, EncryptedPrivateKeyInfo *val)
  405. {
  406. ASN1decoding_t dd;
  407. ASN1octet_t *di;
  408. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  409. return 0;
  410. if (!ASN1Dec_EncryptionAlgorithmIdentifier(dd, 0, &(val)->encryptionAlgorithm))
  411. return 0;
  412. if (!ASN1BERDecOctetString2(dd, 0x4, &(val)->encryptedData))
  413. return 0;
  414. if (!ASN1BERDecEndOfContents(dec, dd, di))
  415. return 0;
  416. return 1;
  417. }
  418. static void ASN1CALL ASN1Free_EncryptedPrivateKeyInfo(EncryptedPrivateKeyInfo *val)
  419. {
  420. if (val) {
  421. ASN1Free_EncryptionAlgorithmIdentifier(&(val)->encryptionAlgorithm);
  422. }
  423. }
  424. static int ASN1CALL ASN1Enc_Attribute(ASN1encoding_t enc, ASN1uint32_t tag, Attribute *val)
  425. {
  426. ASN1uint32_t nLenOff;
  427. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  428. return 0;
  429. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->type))
  430. return 0;
  431. if (!ASN1Enc_AttributeSetValue(enc, 0, &(val)->values))
  432. return 0;
  433. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  434. return 0;
  435. return 1;
  436. }
  437. static int ASN1CALL ASN1Dec_Attribute(ASN1decoding_t dec, ASN1uint32_t tag, Attribute *val)
  438. {
  439. ASN1decoding_t dd;
  440. ASN1octet_t *di;
  441. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  442. return 0;
  443. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->type))
  444. return 0;
  445. if (!ASN1Dec_AttributeSetValue(dd, 0, &(val)->values))
  446. return 0;
  447. if (!ASN1BERDecEndOfContents(dec, dd, di))
  448. return 0;
  449. return 1;
  450. }
  451. static void ASN1CALL ASN1Free_Attribute(Attribute *val)
  452. {
  453. if (val) {
  454. ASN1Free_AttributeSetValue(&(val)->values);
  455. }
  456. }