Skip to content

Commit

Permalink
improve code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
negrel committed May 7, 2024
1 parent 78cd040 commit 675bb17
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 8 deletions.
47 changes: 46 additions & 1 deletion const.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,67 @@
/**
* Size (in bytes) of salt block in encryption content-coding header.
*/
export const SALT_LENGTH = 16;
/**
* Size (in bytes) of record size block in encryption content-coding header.
*/
export const RS_LENGTH = 4;

/**
* Size (in bytes) of idlen block in encryption content-coding header.
*/
export const IDLEN_LENGTH = 1;

/**
* Size (in bytes) of content-encryption key.
*/
export const KEY_LENGTH = 16;

/**
* Size of authentication tag block in encryption content-coding header.
*/
export const TAG_LENGTH = 16;

/**
* Size of a nonce.
*/
export const NONCE_LENGTH = 12;

/**
* Minimum size of an encryption content-coding header.
*/
export const HEADER_LENGTH_MIN = SALT_LENGTH + RS_LENGTH + IDLEN_LENGTH;

/**
* Default size of a record.
*/
export const DEFAULT_RECORD_SIZE = 1024 * 64;
/**
* Minimum size of a record.
*/
export const RECORD_SIZE_MIN = 18;
/**
* Maximum size of a record.
*/
export const RECORD_SIZE_MAX = 2 ** 36 - 31;

export const encoder: TextEncoder = new TextEncoder();
const encoder: TextEncoder = new TextEncoder();

/**
* Content-encryption key info as in https://www.rfc-editor.org/rfc/rfc8188#section-2.2
*/
export const CEK_INFO: Uint8Array = encoder.encode(
"Content-Encoding: aes128gcm\0",
);

/**
* Nonce info as in https://www.rfc-editor.org/rfc/rfc8188#section-2.3
*/
export const NONCE_INFO: Uint8Array = encoder.encode(
"Content-Encoding: nonce\0",
);
/**
* Uint8Array of size 1 containing a single byte of value 1.
* This is mostly used for concatenation with others Uint8Array.
*/
export const ONE_BYTE: Uint8Array = encoder.encode("\x01");
8 changes: 8 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
],
"indentWidth": 2
},
"publish": {
"include": [
"*.ts"
],
"exclude": [
"*_test.ts"
]
},
"imports": {
"@deno/dnt": "jsr:@deno/dnt@0.38.0",
"@std/encoding": "jsr:@std/encoding@0.224.0",
Expand Down
38 changes: 38 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ece_crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
NONCE_LENGTH,
ONE_BYTE,
} from "./const.ts";
import { bytes, encodeBase64Url } from "./deps.ts";
import { bytes } from "./deps.ts";

export interface ECECryptoOptions {
header?: Header | HeaderOptions;
Expand Down
10 changes: 4 additions & 6 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
export { decrypt, encrypt, WithPaddingRecordIterable } from "./ece.ts";
export { Header } from "./header.ts";
export type { HeaderOptions } from "./header.ts";
export { Salt } from "./salt.ts";
export { ECECrypto } from "./ece_crypto.ts";
export type { ECECryptoOptions } from "./ece_crypto.ts";
export * from "./ece.ts";
export * from "./header.ts";
export * from "./salt.ts";
export * from "./ece_crypto.ts";
export * from "./const.ts";

0 comments on commit 675bb17

Please sign in to comment.