File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -108,6 +108,31 @@ impl Session {
108108 . map_err ( Into :: into)
109109 }
110110
111+ /// Remove one [`KeyPackage`] from the database.
112+ ///
113+ /// Succeeds silently if the keypackage does not exist in the database.
114+ ///
115+ /// Implementation note: this must first load and deserialize the keypackage,
116+ /// then remove items from three distinct tables.
117+ pub async fn remove_keypackage ( & self , kp_ref : & KeyPackageRef ) -> Result < ( ) > {
118+ let Some ( kp) = self . load_keypackage ( kp_ref) . await ? else {
119+ return Ok ( ( ) ) ;
120+ } ;
121+
122+ let db = self . crypto_provider . keystore ( ) ;
123+ db. remove :: < StoredKeypackage , _ > ( kp_ref. as_slice ( ) )
124+ . await
125+ . map_err ( KeystoreError :: wrap ( "removing key package from keystore" ) ) ?;
126+ db. remove :: < StoredHpkePrivateKey , _ > ( kp. hpke_init_key ( ) . as_slice ( ) )
127+ . await
128+ . map_err ( KeystoreError :: wrap ( "removing private key from keystore" ) ) ?;
129+ db. remove :: < StoredEncryptionKeyPair , _ > ( kp. leaf_node ( ) . encryption_key ( ) . as_slice ( ) )
130+ . await
131+ . map_err ( KeystoreError :: wrap ( "removing encryption keypair from keystore" ) ) ?;
132+
133+ Ok ( ( ) )
134+ }
135+
111136 /// Generates a single new keypackage
112137 ///
113138 /// # Arguments
Original file line number Diff line number Diff line change @@ -96,4 +96,14 @@ impl TransactionContext {
9696 ) )
9797 . map_err ( Into :: into)
9898 }
99+
100+ /// Remove a [`KeyPackage`] from the keystore.
101+ pub async fn remove_keypackage ( & self , kp_ref : & KeyPackageRef ) -> Result < ( ) > {
102+ let session = self . session ( ) . await ?;
103+ session
104+ . remove_keypackage ( kp_ref)
105+ . await
106+ . map_err ( RecursiveError :: mls_client ( "removing a keypackage for transaction" ) )
107+ . map_err ( Into :: into)
108+ }
99109}
You can’t perform that action at this time.
0 commit comments