-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PM-9423] use observable user encryptor in secret state (#10271)
- Loading branch information
1 parent
82d6b26
commit d26ea1b
Showing
9 changed files
with
128 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,33 @@ | ||
import { Jsonify } from "type-fest"; | ||
|
||
import { UserId } from "@bitwarden/common/types/guid"; | ||
|
||
import { EncString } from "../../platform/models/domain/enc-string"; | ||
import { UserId } from "../../types/guid"; | ||
|
||
/** A classification strategy that protects a type's secrets with | ||
* user-specific information. The specific kind of information is | ||
* determined by the classification strategy. | ||
/** An encryption strategy that protects a type's secrets with | ||
* user-specific keys. This strategy is bound to a specific user. | ||
*/ | ||
export abstract class UserEncryptor { | ||
/** Identifies the user bound to the encryptor. */ | ||
readonly userId: UserId; | ||
|
||
/** Protects secrets in `value` with a user-specific key. | ||
* @param secret the object to protect. This object is mutated during encryption. | ||
* @param userId identifies the user-specific information used to protect | ||
* the secret. | ||
* @returns a promise that resolves to a tuple. The tuple's first property contains | ||
* the encrypted secret and whose second property contains an object w/ disclosed | ||
* properties. | ||
* @throws If `value` is `null` or `undefined`, the promise rejects with an error. | ||
*/ | ||
abstract encrypt<Secret>(secret: Jsonify<Secret>, userId: UserId): Promise<EncString>; | ||
abstract encrypt<Secret>(secret: Jsonify<Secret>): Promise<EncString>; | ||
|
||
/** Combines protected secrets and disclosed data into a type that can be | ||
* rehydrated into a domain object. | ||
* @param secret an encrypted JSON payload containing encrypted secrets. | ||
* @param userId identifies the user-specific information used to protect | ||
* the secret. | ||
* @returns a promise that resolves to the raw state. This state *is not* a | ||
* class. It contains only data that can be round-tripped through JSON, | ||
* and lacks members such as a prototype or bound functions. | ||
* @throws If `secret` or `disclosed` is `null` or `undefined`, the promise | ||
* rejects with an error. | ||
*/ | ||
abstract decrypt<Secret>(secret: EncString, userId: UserId): Promise<Jsonify<Secret>>; | ||
abstract decrypt<Secret>(secret: EncString): Promise<Jsonify<Secret>>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.