Skip to content

Add tsdoc #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion schemaregistry/rest-error.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
/**
* Represents a REST error.
*/
export class RestError extends Error {
status: number;
errorCode: number;

/**
* Creates a new REST error.
* @param message - The error message.
* @param status - The HTTP status code.
* @param errorCode - The error code.
*/
constructor(message: string, status: number, errorCode: number) {
super(message + "; Error code: " + errorCode);
this.status = status;
this.errorCode = errorCode;
}
}
}
3 changes: 3 additions & 0 deletions schemaregistry/rules/encryption/awskms/aws-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export class AwsKmsDriver implements KmsDriver {
static ACCESS_KEY_ID = 'access.key.id'
static SECRET_ACCESS_KEY = 'secret.access.key'

/**
* Register the AWS KMS driver with the KMS registry.
*/
static register(): void {
registerKmsDriver(new AwsKmsDriver())
}
Expand Down
3 changes: 3 additions & 0 deletions schemaregistry/rules/encryption/azurekms/azure-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export class AzureKmsDriver implements KmsDriver {
static CLIENT_ID = 'client.id'
static CLIENT_SECRET = 'client.secret'

/**
* Register the Azure KMS driver with the KMS registry.
*/
static register(): void {
registerKmsDriver(new AzureKmsDriver())
}
Expand Down
3 changes: 3 additions & 0 deletions schemaregistry/rules/encryption/encrypt-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ export class FieldEncryptionExecutor extends FieldRuleExecutor {
client: Client | null = null
clock: Clock

/**
* Register the field encryption executor with the rule registry.
*/
static register(): FieldEncryptionExecutor {
return this.registerWithClock(new Clock())
}
Expand Down
3 changes: 3 additions & 0 deletions schemaregistry/rules/encryption/gcpkms/gcp-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export class GcpKmsDriver implements KmsDriver {
static PRIVATE_KEY_ID = "private.key.id";
static PRIVATE_KEY= "private.key";

/**
* Register the GCP KMS driver with the KMS registry.
*/
static register(): void {
registerKmsDriver(new GcpKmsDriver())
}
Expand Down
3 changes: 3 additions & 0 deletions schemaregistry/rules/encryption/hcvault/hcvault-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export class HcVaultDriver implements KmsDriver {
static TOKEN_ID = 'token.id'
static NAMESPACE = 'namespace'

/**
* Register the HashiCorp Vault driver with the KMS registry.
*/
static register(): void {
registerKmsDriver(new HcVaultDriver())
}
Expand Down
25 changes: 25 additions & 0 deletions schemaregistry/rules/encryption/kms-registry.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import {SecurityException} from "./tink/exception/security_exception";

/**
* Key management service (KMS) driver.
*/
export interface KmsDriver {
getKeyUrlPrefix(): string
newKmsClient(config: Map<string, string>, keyUrl: string): KmsClient
}

/**
* Key management service (KMS) client.
*/
export interface KmsClient {
supported(keyUri: string): boolean
encrypt(plaintext: Buffer): Promise<Buffer>
Expand All @@ -16,10 +22,18 @@ const kmsDrivers: KmsDriver[] = []
const kmsClients: KmsClient[] = []


/**
* Register a KMS driver.
* @param kmsDriver - the KMS driver to register
*/
export function registerKmsDriver(kmsDriver: KmsDriver): void {
kmsDrivers.push(kmsDriver)
}

/**
* Get the KMS driver for the given key URL.
* @param keyUrl - the key URL
*/
export function getKmsDriver(keyUrl: string): KmsDriver {
for (let driver of kmsDrivers) {
if (keyUrl.startsWith(driver.getKeyUrlPrefix())) {
Expand All @@ -29,10 +43,18 @@ export function getKmsDriver(keyUrl: string): KmsDriver {
throw new SecurityException('no KMS driver found for key URL: ' + keyUrl)
}

/**
* Register a KMS client.
* @param kmsClient - the KMS client to register
*/
export function registerKmsClient(kmsClient: KmsClient): void {
kmsClients.push(kmsClient)
}

/**
* Get the KMS client for the given key URL.
* @param keyUrl - the key URL
*/
export function getKmsClient(keyUrl: string): KmsClient | null {
for (let client of kmsClients) {
if (client.supported(keyUrl)) {
Expand All @@ -42,6 +64,9 @@ export function getKmsClient(keyUrl: string): KmsClient | null {
return null
}

/**
* Clear the KMS clients.
*/
export function clearKmsClients(): void {
kmsClients.length = 0
}
Expand Down
3 changes: 3 additions & 0 deletions schemaregistry/rules/encryption/localkms/local-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export class LocalKmsDriver implements KmsDriver {
static PREFIX: string = 'local-kms://'
static SECRET: string = 'secret'

/**
* Register the local KMS driver with the KMS registry.
*/
static register(): void {
registerKmsDriver(new LocalKmsDriver())
}
Expand Down
13 changes: 6 additions & 7 deletions schemaregistry/rules/encryption/tink/aead.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -21,13 +20,13 @@ export abstract class Aead {
* data. The resulting ciphertext allows for checking authenticity and
* integrity of associated data, but does not guarantee its secrecy.
*
* @param plaintext the plaintext to be encrypted. It must be
* @param plaintext - the plaintext to be encrypted. It must be
* non-null, but can also be an empty (zero-length) byte array.
* @param opt_associatedData optional associated data to be
* @param opt_associatedData - optional associated data to be
* authenticated, but not encrypted. A null value is equivalent to an
* empty (zero-length) byte array. For successful decryption the same
* associated data must be provided along with the ciphertext.
* @return resulting ciphertext
* @returns resulting ciphertext
*
*/
abstract encrypt(plaintext: Uint8Array, opt_associatedData?: Uint8Array|null):
Expand All @@ -38,13 +37,13 @@ export abstract class Aead {
* The decryption verifies the authenticity and integrity of the associated
* data, but there are no guarantees wrt. secrecy of that data.
*
* @param ciphertext the ciphertext to be decrypted, must be
* @param ciphertext - the ciphertext to be decrypted, must be
* non-null.
* @param opt_associatedData optional associated data to be
* @param opt_associatedData - optional associated data to be
* authenticated. A null value is equivalent to an empty (zero-length)
* byte array. For successful decryption the same associated data must be
* provided along with the ciphertext.
* @return resulting plaintext
* @returns resulting plaintext
*/
abstract decrypt(
ciphertext: Uint8Array,
Expand Down
2 changes: 0 additions & 2 deletions schemaregistry/rules/encryption/tink/aes_gcm.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -27,7 +26,6 @@ const TAG_SIZE_IN_BITS: number = 128;
/**
* Implementation of AES-GCM.
*
* @final
*/
export class AesGcm extends Aead {
constructor(private readonly key: CryptoKey) {
Expand Down
2 changes: 0 additions & 2 deletions schemaregistry/rules/encryption/tink/aes_siv.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -13,7 +12,6 @@ import * as crypto from 'crypto';
/**
* Implementation of AES-SIV.
*
* @final
*/
export class AesSiv extends Aead {
constructor(private readonly key: Uint8Array) {
Expand Down
49 changes: 21 additions & 28 deletions schemaregistry/rules/encryption/tink/bytes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -8,9 +7,9 @@ import {InvalidArgumentsException} from './exception/invalid_arguments_exception

/**
* Does near constant time byte array comparison.
* @param ba1 The first bytearray to check.
* @param ba2 The second bytearray to check.
* @return If the array are equal.
* @param ba1 - The first bytearray to check.
* @param ba2 - The second bytearray to check.
* @returns If the array are equal.
*/
export function isEqual(ba1: Uint8Array, ba2: Uint8Array): boolean {
if (ba1.length !== ba2.length) {
Expand Down Expand Up @@ -45,10 +44,9 @@ export function concat(...var_args: Uint8Array[]): Uint8Array {

/**
* Converts a non-negative integer number to a 64-bit big-endian byte array.
* @param value The number to convert.
* @return The number as a big-endian byte array.
* @throws {InvalidArgumentsException}
* @static
* @param value - The number to convert.
* @returns The number as a big-endian byte array.
* @throws {@link InvalidArgumentsException}
*/
export function fromNumber(value: number): Uint8Array {
if (Number.isNaN(value) || value % 1 !== 0) {
Expand Down Expand Up @@ -79,10 +77,9 @@ export function fromNumber(value: number): Uint8Array {
/**
* Converts the hex string to a byte array.
*
* @param hex the input
* @return the byte array output
* @throws {!InvalidArgumentsException}
* @static
* @param hex - the input
* @returns the byte array output
* @throws {@link InvalidArgumentsException}
*/
export function fromHex(hex: string): Uint8Array {
if (hex.length % 2 != 0) {
Expand All @@ -99,9 +96,8 @@ export function fromHex(hex: string): Uint8Array {
/**
* Converts a byte array to hex.
*
* @param bytes the byte array input
* @return hex the output
* @static
* @param bytes - the byte array input
* @returns hex the output
*/
export function toHex(bytes: Uint8Array): string {
let result = '';
Expand All @@ -115,11 +111,10 @@ export function toHex(bytes: Uint8Array): string {
/**
* Converts the Base64 string to a byte array.
*
* @param encoded the base64 string
* @param opt_webSafe True indicates we should use the alternative
* @param encoded - the base64 string
* @param opt_webSafe - True indicates we should use the alternative
* alphabet, which does not require escaping for use in URLs.
* @return the byte array output
* @static
* @returns the byte array output
*/
export function fromBase64(encoded: string, opt_webSafe?: boolean): Uint8Array {
if (opt_webSafe) {
Expand All @@ -132,11 +127,10 @@ export function fromBase64(encoded: string, opt_webSafe?: boolean): Uint8Array {
/**
* Base64 encode a byte array.
*
* @param bytes the byte array input
* @param opt_webSafe True indicates we should use the alternative
* @param bytes - the byte array input
* @param opt_webSafe - True indicates we should use the alternative
* alphabet, which does not require escaping for use in URLs.
* @return base64 output
* @static
* @returns base64 - output
*/
export function toBase64(bytes: Uint8Array, opt_webSafe?: boolean): string {
const encoded = window
Expand All @@ -154,9 +148,8 @@ export function toBase64(bytes: Uint8Array, opt_webSafe?: boolean): string {
* Converts a byte string to a byte array. Only support ASCII and Latin-1
* strings, does not support multi-byte characters.
*
* @param str the input
* @return the byte array output
* @static
* @param str - the input
* @returns the byte array output
*/
export function fromByteString(str: string): Uint8Array {
const output = [];
Expand All @@ -173,9 +166,9 @@ export function fromByteString(str: string): Uint8Array {
* characters to which the numbers correspond. Each byte is corresponding to a
* character. Does not support multi-byte characters.
*
* @param bytes Array of numbers representing
* @param bytes - Array of numbers representing
* characters.
* @return Stringification of the array.
* @returns Stringification of the array.
*/
export function toByteString(bytes: Uint8Array): string {
let str = '';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
15 changes: 7 additions & 8 deletions schemaregistry/rules/encryption/tink/hkdf.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/


/**
* @fileoverview An implementation of HKDF, RFC 5869.
* An implementation of HKDF, RFC 5869.
*/
import {InvalidArgumentsException} from './exception/invalid_arguments_exception';

Expand All @@ -16,17 +15,17 @@ import * as Validators from './validators';
/**
* Computes an HKDF.
*
* @param size The length of the generated pseudorandom string in
* @param size - The length of the generated pseudorandom string in
* bytes. The maximal size is 255 * DigestSize, where DigestSize is the size
* of the underlying HMAC.
* @param hash the name of the hash function. Accepted names are SHA-1,
* @param hash - the name of the hash function. Accepted names are SHA-1,
* SHA-256 and SHA-512
* @param ikm Input keying material.
* @param info Context and application specific
* @param ikm - Input keying material.
* @param info - Context and application specific
* information (can be a zero-length array).
* @param opt_salt Salt value (a non-secret random
* @param opt_salt - Salt value (a non-secret random
* value). If not provided, it is set to a string of hash length zeros.
* @return Output keying material (okm).
* @returns Output keying material (okm).
*/
export async function compute(
size: number, hash: string, ikm: Uint8Array, info: Uint8Array,
Expand Down
Loading