mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-17 04:07:51 +01:00
crypto: fix nodejs native encryption causing file corruption
This commit is contained in:
committed by
Abdullah Atta
parent
6d9aa56084
commit
3492bef2c7
@@ -364,7 +364,7 @@ export function to_base64(
|
|||||||
input: string | Uint8Array,
|
input: string | Uint8Array,
|
||||||
variant: base64_variants = base64_variants.URLSAFE_NO_PADDING
|
variant: base64_variants = base64_variants.URLSAFE_NO_PADDING
|
||||||
): string {
|
): string {
|
||||||
const base64 = Buffer.from(toBuffer(input)).toString(
|
const base64 = toBuffer(input).toString(
|
||||||
variant === base64_variants.URLSAFE ||
|
variant === base64_variants.URLSAFE ||
|
||||||
variant === base64_variants.URLSAFE_NO_PADDING
|
variant === base64_variants.URLSAFE_NO_PADDING
|
||||||
? "base64url"
|
? "base64url"
|
||||||
@@ -383,7 +383,9 @@ export function from_hex(input: string): Uint8Array {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function to_string(input: Uint8Array): string {
|
export function to_string(input: Uint8Array): string {
|
||||||
return Buffer.from(input).toString("utf-8");
|
return Buffer.from(input, input.byteOffset, input.byteLength).toString(
|
||||||
|
"utf-8"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
@@ -413,7 +415,7 @@ function toBuffer<TInput extends ToBufferInput>(
|
|||||||
input: TInput
|
input: TInput
|
||||||
): ToBufferResult<TInput> {
|
): ToBufferResult<TInput> {
|
||||||
if (input instanceof Uint8Array) {
|
if (input instanceof Uint8Array) {
|
||||||
return Buffer.from(input.buffer, 0, input.byteLength);
|
return Buffer.from(input.buffer, input.byteOffset, input.byteLength);
|
||||||
} else if (typeof input === "undefined" || input === null) {
|
} else if (typeof input === "undefined" || input === null) {
|
||||||
return undefined as ToBufferResult<TInput>;
|
return undefined as ToBufferResult<TInput>;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user