Skip to content

Commit d58cde2

Browse files
Lighter pointers
1 parent f96e404 commit d58cde2

4 files changed

Lines changed: 20 additions & 11 deletions

File tree

libDER/DER_Decode.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ Deno.test('DERSequence', () => {
3333
assertEquals(spec.end, null);
3434
}
3535
{
36-
const nextItem = new Uint8Ptr(new ArrayBuffer(1));
37-
const end = new Uint8Ptr(nextItem.buffer, nextItem.byteOffset + 1);
36+
const ab = new ArrayBuffer(10);
37+
const nextItem = new Uint8Ptr(ab);
38+
const end = new Uint8Ptr(
39+
nextItem.buffer,
40+
nextItem.byteOffset + ab.byteLength,
41+
);
3842
const spec = new DERSequence(nextItem, end);
3943
assertEquals(spec.nextItem, nextItem);
4044
assertEquals(spec.end, end);

libc/c.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ export type double = number;
7878
*/
7979
export type _const<T> = T;
8080

81+
/**
82+
* Pointer.
83+
*
84+
* @template T Pointer type.
85+
*/
86+
export type _ptr<T> = Record<number, T>;
87+
8188
/**
8289
* Bitfield bits.
8390
*

sec/SecCertificate.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Bool8Ptr, Int32Ptr, Uint8Ptr } from '@hqtsm/struct';
1+
import { Uint8Ptr } from '@hqtsm/struct';
22
import { assertEquals, assertInstanceOf } from '@std/assert';
33
import { INT32_MAX, INT32_MIN, UINT32_MAX } from '../libc/stdint.ts';
44
import { digest } from '../spec/hash.ts';
@@ -48,8 +48,7 @@ Deno.test('SecCertificateCopyIssuerSHA256Digest', async () => {
4848
});
4949

5050
Deno.test('GetDecimalValueOfString', () => {
51-
const value = new Int32Ptr(new ArrayBuffer(4));
52-
value[0] = 42;
51+
const value = [42];
5352
assertEquals(GetDecimalValueOfString('', value), false);
5453
assertEquals(value[0], 42);
5554
assertEquals(GetDecimalValueOfString('.', value), false);
@@ -135,7 +134,7 @@ Deno.test('SecCertificateCreateOidDataFromString', () => {
135134
});
136135

137136
Deno.test('SecCertificateCopyExtensionValue', () => {
138-
const b = new Bool8Ptr(new ArrayBuffer(1));
137+
const b = [false];
139138
const sce = new SecCertificateExtension();
140139
const sc = new __SecCertificate();
141140
const oid = '1.2.3';

sec/SecCertificate.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { toStringTag } from '@hqtsm/class';
2-
import { Int32Ptr, type Ptr } from '@hqtsm/struct';
32
import type { CFIndex } from '../CoreFoundation/CFBase.ts';
43
import type { SubtleCryptoDigest } from '../helpers/crypto.ts';
54
import {
@@ -8,7 +7,7 @@ import {
87
pointerBytes,
98
viewBytes,
109
} from '../helpers/memory.ts';
11-
import type { bool } from '../libc/c.ts';
10+
import type { _ptr, bool } from '../libc/c.ts';
1211
import { INT32_MAX, type int32_t } from '../libc/stdint.ts';
1312
import { DERItem } from '../libDER/DERItem.ts';
1413
import type { SecCertificateRef } from '../Security/SecBase.ts';
@@ -141,7 +140,7 @@ export async function SecCertificateCopyIssuerSHA256Digest(
141140
*/
142141
export function GetDecimalValueOfString(
143142
string: string,
144-
value: Ptr<int32_t>,
143+
value: _ptr<int32_t>,
145144
): bool {
146145
if (string && /^[0-9]+$/.test(string)) {
147146
value[0] = +string | 0;
@@ -179,7 +178,7 @@ export function SecCertificateCreateOidDataFromString(
179178

180179
const parts = string.split('.');
181180
const count = parts.length;
182-
const xp = new Int32Ptr(new ArrayBuffer(4));
181+
const xp = [0];
183182

184183
GetDecimalValueOfString(parts[0], xp);
185184
let x = xp[0] * 40;
@@ -217,7 +216,7 @@ export function SecCertificateCreateOidDataFromString(
217216
export function SecCertificateCopyExtensionValue(
218217
certificate: SecCertificateRef | null,
219218
extensionOID: string | ArrayBufferLikeData | null,
220-
isCritical: Ptr<bool> | null,
219+
isCritical: _ptr<bool> | null,
221220
): Uint8Array<ArrayBuffer> | null {
222221
if (!certificate || !extensionOID) {
223222
return null;

0 commit comments

Comments
 (0)