@hackbg/miscreant-esm
Version:
(ESM port) Misuse resistant symmetric encryption library providing AES-SIV (RFC 5297), AES-PMAC-SIV, and STREAM constructions
60 lines (59 loc) • 1.73 kB
JavaScript
;
var __awaiter = this && this.__awaiter || (function (thisArg, _arguments, P, generator) {
function adopt(value) {
return value instanceof P ? value : new P(function (resolve) {
resolve(value);
});
}
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
}
function rejected(value) {
try {
step(generator["throw"](value));
} catch (e) {
reject(e);
}
}
function step(result) {
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
}
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
});
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.AEAD = void 0;
const webcrypto_1 = require("./providers/webcrypto.dist.cjs");
const siv_1 = require("./siv.dist.cjs");
class AEAD {
static importKey(keyData, alg, provider = new webcrypto_1.WebCryptoProvider()) {
return __awaiter(this, void 0, void 0, function* () {
return new AEAD(yield siv_1.SIV.importKey(keyData, alg, provider));
});
}
constructor(siv) {
this._siv = siv;
}
seal(plaintext, nonce, associatedData = new Uint8Array(0)) {
return __awaiter(this, void 0, void 0, function* () {
return this._siv.seal(plaintext, [associatedData, nonce]);
});
}
open(ciphertext, nonce, associatedData = new Uint8Array(0)) {
return __awaiter(this, void 0, void 0, function* () {
return this._siv.open(ciphertext, [associatedData, nonce]);
});
}
clear() {
this._siv.clear();
return this;
}
}
exports.AEAD = AEAD;