mirror of
https://github.com/bitwarden/browser
synced 2025-12-15 07:43:35 +00:00
[PM-24079] Switch EncryptedString to SDK type (#15796)
* Update usages of sdk to type-safe SDK type * Update sdk version * Update to "toSdk"
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
// FIXME: Update this file to be type safe and remove this and next line
|
||||
// @ts-strict-ignore
|
||||
import { Jsonify, Opaque } from "type-fest";
|
||||
import { Jsonify } from "type-fest";
|
||||
|
||||
import { EncString as SdkEncString } from "@bitwarden/sdk-internal";
|
||||
|
||||
import { EncryptionType, EXPECTED_NUM_PARTS_BY_ENCRYPTION_TYPE } from "../../../platform/enums";
|
||||
import { Encrypted } from "../../../platform/interfaces/encrypted";
|
||||
@@ -10,7 +12,7 @@ import { SymmetricCryptoKey } from "../../../platform/models/domain/symmetric-cr
|
||||
export const DECRYPT_ERROR = "[error: cannot decrypt]";
|
||||
|
||||
export class EncString implements Encrypted {
|
||||
encryptedString?: EncryptedString;
|
||||
encryptedString?: SdkEncString;
|
||||
encryptionType?: EncryptionType;
|
||||
decryptedValue?: string;
|
||||
data?: string;
|
||||
@@ -42,7 +44,11 @@ export class EncString implements Encrypted {
|
||||
return this.data == null ? null : Utils.fromB64ToArray(this.data);
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
toSdk(): SdkEncString {
|
||||
return this.encryptedString;
|
||||
}
|
||||
|
||||
toJSON(): string {
|
||||
return this.encryptedString as string;
|
||||
}
|
||||
|
||||
@@ -56,14 +62,14 @@ export class EncString implements Encrypted {
|
||||
|
||||
private initFromData(encType: EncryptionType, data: string, iv: string, mac: string) {
|
||||
if (iv != null) {
|
||||
this.encryptedString = (encType + "." + iv + "|" + data) as EncryptedString;
|
||||
this.encryptedString = (encType + "." + iv + "|" + data) as SdkEncString;
|
||||
} else {
|
||||
this.encryptedString = (encType + "." + data) as EncryptedString;
|
||||
this.encryptedString = (encType + "." + data) as SdkEncString;
|
||||
}
|
||||
|
||||
// mac
|
||||
if (mac != null) {
|
||||
this.encryptedString = (this.encryptedString + "|" + mac) as EncryptedString;
|
||||
this.encryptedString = (this.encryptedString + "|" + mac) as SdkEncString;
|
||||
}
|
||||
|
||||
this.encryptionType = encType;
|
||||
@@ -73,7 +79,7 @@ export class EncString implements Encrypted {
|
||||
}
|
||||
|
||||
private initFromEncryptedString(encryptedString: string) {
|
||||
this.encryptedString = encryptedString as EncryptedString;
|
||||
this.encryptedString = encryptedString as SdkEncString;
|
||||
if (!this.encryptedString) {
|
||||
return;
|
||||
}
|
||||
@@ -191,4 +197,8 @@ export class EncString implements Encrypted {
|
||||
}
|
||||
}
|
||||
|
||||
export type EncryptedString = Opaque<string, "EncString">;
|
||||
/**
|
||||
* Temporary type mapping until consumers are moved over.
|
||||
* @deprecated - Use SdkEncString directly
|
||||
*/
|
||||
export type EncryptedString = SdkEncString;
|
||||
|
||||
Reference in New Issue
Block a user