Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

Commit

Permalink
Add purpose validation on initialization of key generator
Browse files Browse the repository at this point in the history
  • Loading branch information
Cach30verfl0w committed Jun 12, 2024
1 parent 5768515 commit 198cfbf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class PQCryptoProvider: AbstractProvider(

algorithm("Kyber") {
keyGenerator(
Key.PURPOSE_ENCRYPT or Key.PURPOSE_ENCRYPT,
Key.PURPOSE_ENCRYPT or Key.PURPOSE_DECRYPT,
arrayOf(512, 768, 1024),
1024
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ class KeyGeneratorDelegate<C: Any>(
*/
fun initializer(closure: (KeyGeneratorSpec) -> C) {
this.initializer = { keyGenSpec ->
// TODO: Add validation for purposes
if ((keyGenSpec.purposes and this.keyPurposes) != keyGenSpec.purposes) {
throw IllegalArgumentException("Key purposes ${keyGenSpec.purposes} not supported")
}
KeyGenContext(keyGenSpec, closure(keyGenSpec))
}
}
Expand Down

0 comments on commit 198cfbf

Please sign in to comment.