Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add policy to relevant key-based functions #78

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions witx/proposal_asymmetric_common.witx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
;;; Example usage:
;;;
;;; ```rust
;;; let kp_handle = ctx.keypair_generate(AlgorithmType::Signatures, "RSA_PKCS1_2048_SHA256", None)?;
;;; let policy = ctx.get_policy("Encryption_only_policy)?;"
;;; let kp_handle = ctx.keypair_generate(policy, AlgorithmType::Signatures, "RSA_PKCS1_2048_SHA256", None)?;
;;; ```
(@interface func (export "keypair_generate")
(param $policy $policy)
(param $algorithm_type $algorithm_type)
(param $algorithm string)
(param $options $opt_options)
Expand All @@ -39,9 +41,11 @@
;;; Example usage:
;;;
;;; ```rust
;;; let kp_handle = ctx.keypair_import(AlgorithmType::Signatures, "RSA_PKCS1_2048_SHA256", KeypairEncoding::PKCS8)?;
;;; let policy = ctx.get_policy("Encryption_only_policy)?;"
;;; let kp_handle = ctx.keypair_import(policy, AlgorithmType::Signatures, "RSA_PKCS1_2048_SHA256", KeypairEncoding::PKCS8)?;
;;; ```
(@interface func (export "keypair_import")
(param $policy $policy)
(param $algorithm_type $algorithm_type)
(param $algorithm string)
(param $encoded (@witx const_pointer u8))
Expand Down Expand Up @@ -193,9 +197,11 @@
;;; Example usage:
;;;
;;; ```rust
;;; let policy = ctx.get_policy("Encryption_only_policy)?;"
;;; let pk_handle = ctx.publickey_import(AlgorithmType::Signatures, encoded, PublicKeyEncoding::Sec)?;
;;; ```
(@interface func (export "publickey_import")
(param $policy $policy)
(param $algorithm_type $algorithm_type)
(param $algorithm string)
(param $encoded (@witx const_pointer u8))
Expand Down Expand Up @@ -248,9 +254,11 @@
;;; Example usage:
;;;
;;; ```rust
;;; let pk_handle = ctx.secretkey_import(AlgorithmType::KX, encoded, SecretKeyEncoding::Raw)?;
;;; let policy = ctx.get_policy("Encryption_only_policy)?;"
;;; let pk_handle = ctx.secretkey_import(policy, AlgorithmType::KX, encoded, SecretKeyEncoding::Raw)?;
;;; ```
(@interface func (export "secretkey_import")
(param $policy $policy)
(param $algorithm_type $algorithm_type)
(param $algorithm string)
(param $encoded (@witx const_pointer u8))
Expand Down
19 changes: 19 additions & 0 deletions witx/proposal_common.witx
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@

;;; A managed key or secret expired and cannot be used any more.
$expired

;;; Invalid policy handle
$policy_invalid

;;; Not allowed by policy
$policy_unallowed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems to be redundant with $prohibited_operation

)
)

Expand Down Expand Up @@ -253,6 +259,11 @@
;;; An `array_output` handle is automatically closed after its full content has been consumed.
(typename $array_output (handle))

;;; Key policy document
;;;
;;; This type is used to represent a policy to control how a keypair may be used.
(typename $policy (handle))

;;; A set of options.
;;;
;;; This type is used to set non-default parameters.
Expand Down Expand Up @@ -392,6 +403,14 @@
(result $error (expected (error $crypto_errno)))
)

;;; Get a policy handle
;;;
;;; This function returns a handle for a policy, or an error if the policy does not exist.
(@interface func (export "get_policy")
(param $name string)
(result $error (expected $policy (error $crypto_errno)))
)

;;; Return the length of an `array_output` object.
;;;
;;; This allows a guest to allocate a buffer of the correct size in order to copy the output of a function returning this object type.
Expand Down