@hpke/core
Version:
A Hybrid Public Key Encryption (HPKE) core module for various JavaScript runtimes
62 lines (61 loc) • 1.93 kB
JavaScript
import { ExportError, INPUT_LENGTH_LIMIT, InvalidParamError, } from "@hpke/common";
import { emitNotSupported } from "./utils/emitNotSupported.js";
// b"sec"
const LABEL_SEC = new Uint8Array([115, 101, 99]);
export class ExporterContextImpl {
constructor(api, kdf, exporterSecret) {
Object.defineProperty(this, "_api", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "exporterSecret", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "_kdf", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this._api = api;
this._kdf = kdf;
this.exporterSecret = exporterSecret;
}
async seal(_data, _aad) {
return await emitNotSupported();
}
async open(_data, _aad) {
return await emitNotSupported();
}
async export(exporterContext, len) {
if (exporterContext.byteLength > INPUT_LENGTH_LIMIT) {
throw new InvalidParamError("Too long exporter context");
}
try {
return await this._kdf.labeledExpand(this.exporterSecret, LABEL_SEC, new Uint8Array(exporterContext), len);
}
catch (e) {
throw new ExportError(e);
}
}
}
export class RecipientExporterContextImpl extends ExporterContextImpl {
}
export class SenderExporterContextImpl extends ExporterContextImpl {
constructor(api, kdf, exporterSecret, enc) {
super(api, kdf, exporterSecret);
Object.defineProperty(this, "enc", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this.enc = enc;
return;
}
}