Skip to content

Commit

Permalink
Basic functions with wrap OK - missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ccorsin committed Sep 19, 2023
1 parent fe1f74b commit b81911f
Show file tree
Hide file tree
Showing 20 changed files with 158 additions and 74 deletions.
2 changes: 0 additions & 2 deletions src/anonymization/hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export class Hasher {

/**
* Creates a Hasher instance with the specified hash function and salt.
*
* @param {string} hasherMethod - The name of the hash function to use.
* @param {Iterable<number>|undefined} [salt] - The optional salt to use in the hash function.
*/
Expand Down Expand Up @@ -37,7 +36,6 @@ export class Hasher {

/**
* Applies the hash function to the specified elements and returns the resulting hash value.
*
* @param {string|Iterable<number>} data - The elements to apply the hash function to.
* @returns {string} The resulting hash value as a string.
*/
Expand Down
13 changes: 0 additions & 13 deletions src/anonymization/noise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,27 @@ import {
interface NoiseGenerator {
/**
* Apply noise to a floating point number.
*
* @param data - The input number to apply noise to.
* @returns The result of applying noise to the input number.
*/
apply_on_float: (data: number) => number

/**
* Apply noise to a BigInt.
*
* @param data - The input BigInt to apply noise to.
* @returns The result of applying noise to the input BigInt.
*/
apply_on_int: (data: bigint) => bigint

/**
* Apply noise to a date string.
*
* @param data - The input date string to apply noise to.
* @returns The result of applying noise to the input date string.
*/
apply_on_date: (data: string) => string

/**
* Apply correlated noise to an array of floating point numbers.
*
* @param data - The input array of floating point numbers to apply correlated noise to.
* @param factors - The array of correlation factors to use.
* @returns The result of applying correlated noise to the input array of floating point numbers.
Expand All @@ -45,7 +41,6 @@ interface NoiseGenerator {

/**
* Apply correlated noise to an array of BigInts.
*
* @param data - The input array of BigInts to apply correlated noise to.
* @param factors - The array of correlation factors to use.
* @returns The result of applying correlated noise to the input array of BigInts.
Expand All @@ -57,7 +52,6 @@ interface NoiseGenerator {

/**
* Apply correlated noise to an array of date strings.
*
* @param data - The input array of date strings to apply correlated noise to.
* @param factors - The array of correlation factors to use.
* @returns The result of applying correlated noise to the input array of date strings.
Expand All @@ -79,7 +73,6 @@ class Noise {

/**
* Creates a new instance of `Noise`.
*
* @param noise - The noise generator to use.
*/
constructor(noise: NoiseGenerator) {
Expand All @@ -88,7 +81,6 @@ class Noise {

/**
* Applies noise to the input data.
*
* @param data - The input data to apply noise to.
* @returns The input data with noise applied.
* @throws An error if the type of `data` is not supported.
Expand All @@ -107,7 +99,6 @@ class Noise {

/**
* Applies correlated noise to the input data.
*
* @param data - The input data to apply noise to.
* @param factors - The factors to use for applying noise.
* @returns The input data with noise applied.
Expand Down Expand Up @@ -161,13 +152,11 @@ class Noise {

/**
* A class representing a noise generator with parameters.
*
* @augments Noise
*/
export class NoiseWithParameters extends Noise {
/**
* Creates a new instance of `NoiseWithParameters`.
*
* @param methodName - the noise distribution to use ("Gaussian" or "Laplace")
* @param mean - The mean value for generating noise.
* @param stdDev - The standard deviation value for generating noise.
Expand All @@ -179,13 +168,11 @@ export class NoiseWithParameters extends Noise {

/**
* A class representing a noise generator with bounds.
*
* @augments Noise
*/
export class NoiseWithBounds extends Noise {
/**
* Creates a new instance of `NoiseWithBounds`.
*
* @param methodName - the noise distribution to use ("Gaussian", "Laplace" or "Uniform")
* @param minBound - The minimum bound for generating noise.
* @param maxBound - The maximum bound for generating noise.
Expand Down
5 changes: 0 additions & 5 deletions src/anonymization/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export class NumberAggregator {
private readonly _numberAggregator: WebAssemblyNumberAggregator
/**
* Creates an instance of NumberAggregator.
*
* @param powerOfTen The desired power of ten to round the measurements to.
*/
constructor(powerOfTen: number) {
Expand All @@ -21,7 +20,6 @@ export class NumberAggregator {

/**
* Applies the number aggregator on the provided data.
*
* @param data The number or bigint to apply the number aggregator on.
* @returns The rounded value of the data.
* @throws An error if the type of data is not supported.
Expand All @@ -38,15 +36,13 @@ export class NumberAggregator {
}
/**
* A data anonymization technique to round dates to the unit of time specified.
*
* @class
*/
export class DateAggregator {
private readonly _dateAggregator: WebAssemblyDateAggregator

/**
* Creates a new instance of the `DateAggregator`.
*
* @param {string} timeUnit - The unit of time to round the date to.
*/
constructor(timeUnit: string) {
Expand All @@ -55,7 +51,6 @@ export class DateAggregator {

/**
* Applies the `DateAggregator` to the given date.
*
* @param {string} data - The date to apply the `DateAggregator` to.
* @returns {string} - The rounded date string.
* @throws {Error} - If the input data is not a valid date string.
Expand Down
4 changes: 0 additions & 4 deletions src/cover_crypt/decryption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export class CoverCryptHybridDecryption {

/**
* Decrypts a CoverCrypt ciphertext header using the given user decryption key
*
* @param {Uint8Array} encryptedHeader CoverCrypt encrypted header
* @param {object} options Additional optional options to the encryption
* @param {Uint8Array} options.authenticationData Data use to authenticate the encrypted value when decrypting (if use, should be use during
Expand Down Expand Up @@ -57,7 +56,6 @@ export class CoverCryptHybridDecryption {

/**
* Decrypts a AES256-GCM block
*
* @param {Uint8Array} symmetricKey AES key
* @param {Uint8Array} encryptedBytes Encrypted block
* @param {object} options Additional optional options to the encryption
Expand Down Expand Up @@ -85,7 +83,6 @@ export class CoverCryptHybridDecryption {

/**
* Hybrid decrypt wrapper: CoverCrypt decrypt then AES decrypt
*
* @param {Uint8Array} ciphertext the encrypted data
* @param {object} options Additional optional options to the encryption
* @param {Uint8Array} options.authenticationData Data use to authenticate the encrypted value when decrypting (if use, should be use during
Expand All @@ -103,7 +100,6 @@ export class CoverCryptHybridDecryption {

/**
* Hybrid decrypt wrapper: CoverCrypt decrypt then AES decrypt
*
* @param decryptionKey the user key to decrypt
* @param {Uint8Array} ciphertext the encrypted data
* @param {object} options Additional optional options to the encryption
Expand Down
4 changes: 0 additions & 4 deletions src/cover_crypt/encryption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export class CoverCryptHybridEncryption {

/**
* Generate and encrypt a symmetric key using the public key and policy.
*
* @param {string} accessPolicy Encrypt with this access policy
* @param {object} options Additional optional options to the encryption
* @param {Uint8Array} options.headerMetadata Data encrypted in the header
Expand Down Expand Up @@ -77,7 +76,6 @@ export class CoverCryptHybridEncryption {

/**
* Encrypts a AES256-GCM block
*
* @param {Uint8Array} symmetricKey Symmetric key to use to encrypt
* @param {Uint8Array} plaintext Stuff to encrypt
* @param {object} options Additional optional options to the encryption
Expand Down Expand Up @@ -105,7 +103,6 @@ export class CoverCryptHybridEncryption {

/**
* Hybrid encrypt wrapper: CoverCrypt encrypt then AES encrypt
*
* @param {string} accessPolicy Encrypt with this access policy
* @param {Uint8Array} plaintext Stuff to encrypt
* @param {object} options Additional optional options to the encryption
Expand Down Expand Up @@ -133,7 +130,6 @@ export class CoverCryptHybridEncryption {

/**
* Hybrid encrypt wrapper: CoverCrypt encrypt then AES encrypt
*
* @param {Policy} policy CoverCrypt global policy
* @param {Uint8Array} publicKey Master public key
* @param {string} accessPolicy Encrypt with this access policy
Expand Down
5 changes: 0 additions & 5 deletions src/cover_crypt/interfaces/access_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export class AccessPolicy {
/**
* Create an Access Policy from a boolean expression over the attributes e.g.
* (Department::MKG || Department::FIN) && Security Level::Confidential
*
* @param {string} booleanAccessPolicy the boolean expression
*/
constructor(booleanAccessPolicy: string) {
Expand All @@ -23,7 +22,6 @@ export class AccessPolicy {

/**
* Packages the access policy into a vendor attribute to include in a user decryption key
*
* @returns {VendorAttributes} the Access Policy as a VendorAttributes
*/
public async toVendorAttribute(): Promise<VendorAttributes> {
Expand All @@ -36,7 +34,6 @@ export class AccessPolicy {

/**
* Recover the Access Policy from the key attributes, throws otherwise
*
* @param {Attributes} attributes the key attributes to parse
* @returns {AccessPolicy} the Access Policy
*/
Expand All @@ -60,7 +57,6 @@ export class AccessPolicy {
/**
* Attempt to extract the Access Policy from a CoverCrypt User Decryption Key
* Throws if not found
*
* @param {PrivateKey} key the CoverCrypt User Decryption Key
* @returns {AccessPolicy} the recovered Access Policy
*/
Expand All @@ -79,7 +75,6 @@ export class AccessPolicy {
}
/**
* Convert a JSON KMIP access policy into a boolean access policy
*
* @param {string} jsonAccessPolicy the KMIP JSON access policy
* @returns {string} the boolean access policy
*/
Expand Down
1 change: 0 additions & 1 deletion src/cover_crypt/interfaces/encrypted_header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export class EncryptedHeader {

/**
* Deserialize a encrypted header.
*
* @param encryptedHeaderBytes an encrypted header
* @returns the object deserialized
*/
Expand Down
1 change: 0 additions & 1 deletion src/cover_crypt/interfaces/encryption_parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export class Metadata {

/**
* This function convert Metadata to JSON Metadata and returns the corresponding bytes
*
* @returns {Uint8Array} a byte array of the JSON encoding Metadata
*/
public toJsonEncoded(): Uint8Array {
Expand Down
1 change: 0 additions & 1 deletion src/cover_crypt/interfaces/plaintext_header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export class PlaintextHeader {

/**
* Deserialize a clear text header.
*
* @param plaintextHeader a raw header
* @returns the object deserialized
*/
Expand Down
4 changes: 0 additions & 4 deletions src/cover_crypt/interfaces/policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export class Policy {

/**
* Packages the policy into a vendor attribute to include in a key
*
* @returns {VendorAttributes} the Policy as a VendorAttributes
*/
public toVendorAttribute(): VendorAttributes {
Expand All @@ -56,7 +55,6 @@ export class Policy {

/**
* Recover the Policy from the key attributes, throws otherwise
*
* @param {Attributes} attributes the key attributes to parse
* @returns {Policy} the Policy
*/
Expand All @@ -78,7 +76,6 @@ export class Policy {
/**
* Attempt to extract the Policy from a CoverCrypt public or private key
* Throws if not found
*
* @param {PrivateKey | PublicKey} key the CoverCrypt key
* @returns {Policy} the recovered Policy
*/
Expand All @@ -88,7 +85,6 @@ export class Policy {

/**
* Returns the policy bytes.
*
* @returns {Uint8Array} the string
*/
public toBytes(): Uint8Array {
Expand Down
6 changes: 0 additions & 6 deletions src/cover_crypt/key_generation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export class CoverCryptMasterKey {
export class CoverCryptKeyGeneration {
/**
* Generate the Master Key Par
*
* @param {Policy} policy the policy to use
* @returns {CoverCryptMasterKey} the master keys
*/
Expand All @@ -51,7 +50,6 @@ export class CoverCryptKeyGeneration {

/**
* Generate a User Decryption Key
*
* @param {Uint8Array} masterSecretKeyBytes The Master Private Key Bytes
* @param {string} accessPolicy the access policy as a boolean expression
* e.g. (Department::MKG || Department::FIN) && Security Level::Medium Secret
Expand All @@ -70,7 +68,6 @@ export class CoverCryptKeyGeneration {
* Rotate attributes in the given policy
*
* Note: this does NOT refresh the keys
*
* @param {string[]} attributes to rotate
* e.g. ["Department::MKG" , "Department::FIN"]
* @param {Policy} policy the policy
Expand All @@ -83,7 +80,6 @@ export class CoverCryptKeyGeneration {

/**
* Generate the Master Key Par
*
* @param {Policy} policy the policy to use
* @returns {CoverCryptMasterKey} the master keys
*/
Expand All @@ -98,7 +94,6 @@ export function generateMasterKeys(policy: Policy): CoverCryptMasterKey {

/**
* Generate a User Decryption Key
*
* @param {Uint8Array} masterSecretKeyBytes The Master Private Key Bytes
* @param {string} accessPolicy the access policy as a boolean expression
* e.g. (Department::MKG || Department::FIN) && Security Level::Medium Secret
Expand All @@ -123,7 +118,6 @@ export function generateUserSecretKey(
* Rotate attributes in the given policy
*
* Note: this does NOT refresh the keys
*
* @param {string[]} attributes to rotate
* e.g. ["Department::MKG" , "Department::FIN"]
* @param {Policy} policy the policy
Expand Down
2 changes: 0 additions & 2 deletions src/ecies/ecies_salsa_seal_box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export class EciesSalsaSealBox {
/**
* The function encrypts a plaintext message using the ECIES-Salsa20 encryption
* algorithm with a given public key and authenticated data.
*
* @param {string | Uint8Array} plaintext - The `plaintext` parameter is the
* message that you want to encrypt. It can be either a string or a Uint8Array
* (an array of bytes).
Expand Down Expand Up @@ -48,7 +47,6 @@ export class EciesSalsaSealBox {

/**
* The function decrypts a ciphertext using a private key and authenticated data.
*
* @param {string | Uint8Array} ciphertext - The `ciphertext` parameter is the
* encrypted data that you want to decrypt. It can be either a string or a
* Uint8Array, which represents the encrypted data in either text or binary
Expand Down
Loading

0 comments on commit b81911f

Please sign in to comment.