|
| 1 | +import { Bool8Ptr, Int32Ptr, Uint8Ptr } from '@hqtsm/struct'; |
1 | 2 | import { assertEquals, assertInstanceOf } from '@std/assert'; |
2 | 3 | import { INT32_MAX, INT32_MIN, UINT32_MAX } from '../libc/stdint.ts'; |
3 | 4 | import { digest } from '../spec/hash.ts'; |
4 | 5 | import { |
5 | 6 | __SecCertificate, |
6 | 7 | GetDecimalValueOfString, |
| 8 | + SecCertificateCopyExtensionValue, |
7 | 9 | SecCertificateCopyIssuerSHA256Digest, |
8 | 10 | SecCertificateCopySHA1Digest, |
9 | 11 | SecCertificateCreateOidDataFromString, |
| 12 | + SecCertificateExtension, |
10 | 13 | SecCertificateIsOidString, |
11 | 14 | } from './SecCertificate.ts'; |
12 | | -import { Int32Ptr, Uint8Ptr } from '@hqtsm/struct'; |
13 | 15 |
|
14 | 16 | export const ABCD = new Uint8Array([...'ABCD'].map((c) => c.charCodeAt(0))); |
15 | 17 |
|
@@ -131,3 +133,35 @@ Deno.test('SecCertificateCreateOidDataFromString', () => { |
131 | 133 | new Uint8Array([40 + 39, 0x87, 0xFF, 0xFF, 0xFF, 0x7F]), |
132 | 134 | ); |
133 | 135 | }); |
| 136 | + |
| 137 | +Deno.test('SecCertificateCopyExtensionValue', () => { |
| 138 | + const b = new Bool8Ptr(new ArrayBuffer(1)); |
| 139 | + const sce = new SecCertificateExtension(); |
| 140 | + const sc = new __SecCertificate(); |
| 141 | + const oid = '1.2.3'; |
| 142 | + const oidData = SecCertificateCreateOidDataFromString(oid)!; |
| 143 | + |
| 144 | + sce.extnID.data = new Uint8Ptr(oidData.buffer); |
| 145 | + sce.extnID.length = oidData.byteLength; |
| 146 | + sce.critical = true; |
| 147 | + sce.extnValue.data = new Uint8Ptr(ABCD.buffer.slice()); |
| 148 | + sce.extnValue.length = ABCD.byteLength; |
| 149 | + |
| 150 | + sc._extensionCount = 1; |
| 151 | + sc._extensions = [sce]; |
| 152 | + |
| 153 | + assertEquals(SecCertificateCopyExtensionValue(null, null, null), null); |
| 154 | + assertEquals(SecCertificateCopyExtensionValue(sc, null, null), null); |
| 155 | + assertEquals(SecCertificateCopyExtensionValue(sc, '', null), null); |
| 156 | + assertEquals(SecCertificateCopyExtensionValue(sc, 'BAD', null), null); |
| 157 | + |
| 158 | + assertEquals(SecCertificateCopyExtensionValue(sc, oid, b), ABCD); |
| 159 | + assertEquals(b[0], true); |
| 160 | + |
| 161 | + sce.critical = false; |
| 162 | + |
| 163 | + assertEquals(SecCertificateCopyExtensionValue(sc, oidData, b), ABCD); |
| 164 | + assertEquals(b[0], false); |
| 165 | + |
| 166 | + assertEquals(SecCertificateCopyExtensionValue(sc, '1.1.1', b), null); |
| 167 | +}); |
0 commit comments