AzureKeyVault/R/stored_key.R

96 строки
3.1 KiB
R
Исходник Обычный вид История

2019-04-11 11:42:32 +03:00
stored_key <- R6::R6Class("stored_key", inherit=stored_object,
2019-04-11 08:00:53 +03:00
public=list(
2019-04-11 11:42:32 +03:00
type="keys",
2019-04-11 08:00:53 +03:00
key=NULL,
2019-04-11 11:42:32 +03:00
initialize=function(...)
2019-04-11 08:00:53 +03:00
{
2019-04-11 11:42:32 +03:00
super$initialize(...)
2019-04-11 08:00:53 +03:00
if(is.null(self$version))
self$version <- basename(self$key$kid)
},
2019-04-11 08:18:27 +03:00
encrypt=function(plaintext, algorithm=c("RSA-OAEP", "RSA-OAEP-256", "RSA1_5"))
2019-04-11 08:00:53 +03:00
{
if(!is.raw(plaintext) && !is.character(plaintext) && length(plaintext) != 1)
stop("Can only encrypt raw or character plaintext")
body <- list(
alg=match.arg(algorithm),
value=plaintext
)
self$do_operation("encrypt", body=body, encode="json", http_verb="POST")$value
},
2019-04-11 08:18:27 +03:00
decrypt=function(ciphertext, algorithm=c("RSA-OAEP", "RSA-OAEP-256", "RSA1_5"))
2019-04-11 08:00:53 +03:00
{
if(!is.raw(ciphertext) && !is.character(ciphertext) && length(ciphertext) != 1)
stop("Can only decrypt raw or character ciphertext")
body <- list(
alg=match.arg(algorithm),
value=ciphertext
)
self$do_operation("decrypt", body=body, encode="json", http_verb="POST")$value
},
2019-04-11 08:18:27 +03:00
sign=function(digest,
2019-04-11 08:00:53 +03:00
algorithm=c("ES256", "ES256K", "ES384", "ES512", "PS256",
2019-04-11 08:18:27 +03:00
"PS384", "PS512", "RS256", "RS384", "RS512"))
2019-04-11 08:00:53 +03:00
{
if(!is.raw(digest) && !is.character(digest) && length(digest) != 1)
stop("Can only sign raw or character digest")
body <- list(
alg=match.arg(algorithm),
2019-04-11 08:33:11 +03:00
value=jose::base64url_encode(digest)
2019-04-11 08:00:53 +03:00
)
self$do_operation("sign", body=body, encode="json", http_verb="POST")$value
},
2019-04-11 08:18:27 +03:00
verify=function(signature, digest,
2019-04-11 08:00:53 +03:00
algorithm=c("ES256", "ES256K", "ES384", "ES512", "PS256",
2019-04-11 08:18:27 +03:00
"PS384", "PS512", "RS256", "RS384", "RS512"))
2019-04-11 08:00:53 +03:00
{
if(!is.raw(signature) && !is.character(signature) && length(signature) != 1)
stop("Can only verify raw or character signature")
if(!is.raw(digest) && !is.character(digest) && length(digest) != 1)
stop("Can only verify raw or character digest")
body <- list(
alg=match.arg(algorithm),
2019-04-11 08:33:11 +03:00
digest=jose::base64url_encode(digest),
2019-04-11 08:00:53 +03:00
value=signature
)
self$do_operation("verify", body=body, encode="json", http_verb="POST")$value
},
2019-04-11 08:18:27 +03:00
wrap=function(value, algorithm=c("RSA-OAEP", "RSA-OAEP-256", "RSA1_5"))
2019-04-11 08:00:53 +03:00
{
if(!is.raw(value) && !is.character(value) && length(value) != 1)
stop("Can only wrap raw or character input")
body <- list(
alg=match.arg(algorithm),
value=value
)
self$do_operation("wrapkey", body=body, encode="json", http_verb="POST")$value
},
2019-04-11 08:18:27 +03:00
unwrap=function(value, algorithm=c("RSA-OAEP", "RSA-OAEP-256", "RSA1_5"))
2019-04-11 08:00:53 +03:00
{
if(!is.raw(value) && !is.character(value) && length(value) != 1)
stop("Can only wrap raw or character input")
body <- list(
alg=match.arg(algorithm),
value=value
)
self$do_operation("unwrapkey", body=body, encode="json", http_verb="POST")$value
}
))