1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-20 10:13:31 +00:00

[EC-281] Add de/serialization methods to CipherView objects (#2970)

This commit is contained in:
Thomas Rittson
2022-08-05 08:07:24 +10:00
committed by GitHub
parent ee0d87690b
commit 8626e1d4e6
36 changed files with 349 additions and 70 deletions

View File

@@ -1,5 +1,8 @@
import { Jsonify } from "type-fest";
import { Utils } from "@bitwarden/common/misc/utils";
import { EncryptionType } from "../../enums/encryptionType";
import { Utils } from "../../misc/utils";
export class SymmetricCryptoKey {
key: ArrayBuffer;
@@ -55,21 +58,17 @@ export class SymmetricCryptoKey {
}
}
static initFromJson(jsonResult: SymmetricCryptoKey): SymmetricCryptoKey {
if (jsonResult == null) {
return jsonResult;
toJSON() {
// The whole object is constructed from the initial key, so just store the B64 key
return { keyB64: this.keyB64 };
}
static fromJSON(obj: Jsonify<SymmetricCryptoKey>): SymmetricCryptoKey {
if (obj == null) {
return null;
}
if (jsonResult.keyB64 != null) {
jsonResult.key = Utils.fromB64ToArray(jsonResult.keyB64).buffer;
}
if (jsonResult.encKeyB64 != null) {
jsonResult.encKey = Utils.fromB64ToArray(jsonResult.encKeyB64).buffer;
}
if (jsonResult.macKeyB64 != null) {
jsonResult.macKey = Utils.fromB64ToArray(jsonResult.macKeyB64).buffer;
}
return jsonResult;
const arrayBuffer = Utils.fromB64ToArray(obj.keyB64).buffer;
return new SymmetricCryptoKey(arrayBuffer);
}
}