tink-crypto
Version:
A multi-language, cross-platform library that provides cryptographic APIs that are secure, easy to use correctly, and hard(er) to misuse.
95 lines (94 loc) • 2.96 kB
TypeScript
/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { PbKeysetKey, PbKeyStatusType, PbOutputPrefixType } from './proto';
import { Constructor } from './util';
/**
* Auxiliary class for PrimitiveSet
* Entry-objects hold individual instances of primitives in the set.
*
* @template P
* @final
*/
export declare class Entry<P> {
private readonly primitive;
private readonly identifier;
private readonly keyStatus;
private readonly outputPrefixType;
constructor(primitive: P, identifier: Uint8Array, keyStatus: PbKeyStatusType, outputPrefixType: PbOutputPrefixType);
getPrimitive(): P;
getIdentifier(): Uint8Array;
getKeyStatus(): PbKeyStatusType;
getOutputPrefixType(): PbOutputPrefixType;
}
/**
* A container class for a set of primitives (i.e. implementations of
* cryptographic primitives offered by Tink). It provides also additional
* properties for the primitives it holds. In particular, one of the primitives
* in the set can be distinguished as "the primary" one.
*
* PrimitiveSet is an auxiliary class used for supporting key rotation:
* primitives in a set correspond to keys in a keyset. Users will usually work
* with primitive instances which essentially wrap primitive sets. For example
* an instance of an Aead-primitive for a given keyset holds a set of
* Aead-primitives corresponding to the keys in the keyset, and uses the set
* members to do the actual crypto operations: to encrypt data the primary
* Aead-primitive from the set is used, and upon decryption the ciphertext's
* prefix determines the identifier of the primitive from the set.
*
* PrimitiveSet is a public class to allow its use in implementations of custom
* primitives.
*
* @final
*/
export declare class PrimitiveSet<P> {
private readonly primitiveType;
private primary;
private readonly identifierToPrimitivesMap;
constructor(primitiveType: Constructor<P>);
/**
* Returns the type of primitives contained in this set.
*
*/
getPrimitiveType(): Constructor<P>;
/**
* Creates an entry in the primitive table and returns it.
*
*
*/
addPrimitive(primitive: P, key: PbKeysetKey): Entry<P>;
/**
* Returns the entry with the primary primitive.
*
*/
getPrimary(): Entry<P> | null;
/**
* Sets given Entry as the primary one.
*
*/
setPrimary(primitive: Entry<P>): void;
/**
* Returns all primitives using RAW prefix.
*
*/
getRawPrimitives(): Array<Entry<P>>;
/**
* Returns the entries with primitive identified with identifier.
*
*
*/
getPrimitives(identifier: Uint8Array): Array<Entry<P>>;
/**
* Returns a set of primitives which corresponds to the given identifier.
*
*
*/
private getPrimitivesFromMap;
/**
* Add primitive to map.
*
*/
private addPrimitiveToMap;
}