@mxjp/binary 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/base64.d.ts +2 -2
- package/dist/bytes.d.ts +6 -0
- package/dist/bytes.js +18 -0
- package/dist/bytes.js.map +1 -1
- package/package.json +1 -1
- package/src/base64.ts +3 -3
- package/src/bytes.ts +19 -0
package/dist/base64.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export declare function base64UrlEncode(bytes: Bytes, padding?: boolean): string
|
|
|
26
26
|
*
|
|
27
27
|
* @param value The text to decode.
|
|
28
28
|
*/
|
|
29
|
-
export declare function base64Decode(value: string): Uint8Array
|
|
29
|
+
export declare function base64Decode(value: string): Uint8Array<ArrayBuffer>;
|
|
30
30
|
/**
|
|
31
31
|
* Decode a base64 url encoded text with optional trailing padding.
|
|
32
32
|
*
|
|
@@ -36,4 +36,4 @@ export declare function base64Decode(value: string): Uint8Array;
|
|
|
36
36
|
*
|
|
37
37
|
* @param value The text to decode.
|
|
38
38
|
*/
|
|
39
|
-
export declare function base64UrlDecode(value: string): Uint8Array
|
|
39
|
+
export declare function base64UrlDecode(value: string): Uint8Array<ArrayBuffer>;
|
package/dist/bytes.d.ts
CHANGED
|
@@ -8,3 +8,9 @@ export declare function isArrayBuffer(value: unknown): value is ArrayBuffer;
|
|
|
8
8
|
* Check if the specified value is exactly a {@link Uint8Array `Uint8Array<ArrayBuffer>`}.
|
|
9
9
|
*/
|
|
10
10
|
export declare function isUint8Array(value: unknown): value is Uint8Array<ArrayBuffer>;
|
|
11
|
+
/**
|
|
12
|
+
* Check if the specified bytes are equal in length and content.
|
|
13
|
+
*
|
|
14
|
+
* This is **not** a constant time comparison.
|
|
15
|
+
*/
|
|
16
|
+
export declare function bytesEqual(a: Bytes, b: Bytes): boolean;
|
package/dist/bytes.js
CHANGED
|
@@ -21,4 +21,22 @@ export function isArrayBuffer(value) {
|
|
|
21
21
|
export function isUint8Array(value) {
|
|
22
22
|
return value instanceof Uint8Array && value.constructor === Uint8Array && isArrayBuffer(value.buffer);
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Check if the specified bytes are equal in length and content.
|
|
26
|
+
*
|
|
27
|
+
* This is **not** a constant time comparison.
|
|
28
|
+
*/
|
|
29
|
+
export function bytesEqual(a, b) {
|
|
30
|
+
a = asUint8Array(a);
|
|
31
|
+
b = asUint8Array(b);
|
|
32
|
+
if (a.byteLength !== b.byteLength) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
for (let i = 0; i < a.byteLength; i++) {
|
|
36
|
+
if (a[i] !== b[i]) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
24
42
|
//# sourceMappingURL=bytes.js.map
|
package/dist/bytes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bytes.js","sourceRoot":"","sources":["../src/bytes.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,YAAY,CAAC,KAAY;IACxC,IAAI,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;SAAM,IAAI,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;QAChC,OAAO,KAAK,CAAC;IACd,CAAC;SAAM,CAAC;QACP,MAAM,IAAI,SAAS,EAAE,CAAC;IACvB,CAAC;AACF,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC3C,OAAO,KAAK,YAAY,WAAW,IAAI,KAAK,CAAC,WAAW,KAAK,WAAW,CAAC;AAC1E,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,KAAc;IAC1C,OAAO,KAAK,YAAY,UAAU,IAAI,KAAK,CAAC,WAAW,KAAK,UAAU,IAAI,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;A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ED
package/src/base64.ts
CHANGED
|
@@ -45,7 +45,7 @@ function encode(bytes: Uint8Array<ArrayBuffer>, map: Uint8Array<ArrayBuffer>, pa
|
|
|
45
45
|
return value;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
function decode(value: string, map: Uint16Array): Uint8Array {
|
|
48
|
+
function decode(value: string, map: Uint16Array): Uint8Array<ArrayBuffer> {
|
|
49
49
|
if (typeof value !== "string") {
|
|
50
50
|
throw new TypeError();
|
|
51
51
|
}
|
|
@@ -128,7 +128,7 @@ export function base64UrlEncode(bytes: Bytes, padding = false): string {
|
|
|
128
128
|
*
|
|
129
129
|
* @param value The text to decode.
|
|
130
130
|
*/
|
|
131
|
-
export function base64Decode(value: string): Uint8Array {
|
|
131
|
+
export function base64Decode(value: string): Uint8Array<ArrayBuffer> {
|
|
132
132
|
return decode(value, ASCII_TO_BASE64);
|
|
133
133
|
}
|
|
134
134
|
|
|
@@ -141,6 +141,6 @@ export function base64Decode(value: string): Uint8Array {
|
|
|
141
141
|
*
|
|
142
142
|
* @param value The text to decode.
|
|
143
143
|
*/
|
|
144
|
-
export function base64UrlDecode(value: string): Uint8Array {
|
|
144
|
+
export function base64UrlDecode(value: string): Uint8Array<ArrayBuffer> {
|
|
145
145
|
return decode(value, ASCII_TO_BASE64URL);
|
|
146
146
|
}
|
package/src/bytes.ts
CHANGED
|
@@ -24,3 +24,22 @@ export function isArrayBuffer(value: unknown): value is ArrayBuffer {
|
|
|
24
24
|
export function isUint8Array(value: unknown): value is Uint8Array<ArrayBuffer> {
|
|
25
25
|
return value instanceof Uint8Array && value.constructor === Uint8Array && isArrayBuffer(value.buffer);
|
|
26
26
|
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Check if the specified bytes are equal in length and content.
|
|
30
|
+
*
|
|
31
|
+
* This is **not** a constant time comparison.
|
|
32
|
+
*/
|
|
33
|
+
export function bytesEqual(a: Bytes, b: Bytes): boolean {
|
|
34
|
+
a = asUint8Array(a);
|
|
35
|
+
b = asUint8Array(b);
|
|
36
|
+
if (a.byteLength !== b.byteLength) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
for (let i = 0; i < a.byteLength; i++) {
|
|
40
|
+
if (a[i] !== b[i]) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
}
|