diff options
author | Technorama team <oss-ruby@technorama.net> | 2003-04-22 04:58:26 +0000 |
---|---|---|
committer | Technorama team <oss-ruby@technorama.net> | 2003-04-22 04:58:26 +0000 |
commit | b6a752b289512c75c08f1ad09bf58fcd5d756bef (patch) | |
tree | e2d9eb67a8441cff263cb629a0b953ca60d50e6b /ossl_cipher.c | |
parent | b39dc02357b1f41ae2f8fc234c4a49e74043fb71 (diff) | |
download | ruby-openssl-history-b6a752b289512c75c08f1ad09bf58fcd5d756bef.tar.gz |
add ability to set padding
Diffstat (limited to 'ossl_cipher.c')
-rw-r--r-- | ossl_cipher.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/ossl_cipher.c b/ossl_cipher.c index 1ed745b..c5e6295 100644 --- a/ossl_cipher.c +++ b/ossl_cipher.c @@ -298,12 +298,28 @@ ossl_cipher_set_iv(VALUE self, VALUE iv) StringValue(iv); GetCipher(self, ctx); + if (RSTRING(iv)->len < EVP_CIPHER_CTX_iv_length(ctx)) + ossl_raise(eCipherError, "iv length too short"); + if (EVP_CipherInit(ctx, NULL, NULL, RSTRING(iv)->ptr, -1) != 1) ossl_raise(eCipherError, ""); return Qnil; } +static VALUE +ossl_cipher_set_padding(VALUE self, VALUE padding) +{ + EVP_CIPHER_CTX *ctx; + + GetCipher(self, ctx); + + if (EVP_CIPHER_CTX_set_padding(ctx, NUM2INT(padding)) != 1) + ossl_raise(eCipherError, ""); + + return Qnil; +} + #define CIPHER_0ARG_INT(func) \ static VALUE \ ossl_cipher_##func(VALUE self) \ @@ -350,5 +366,7 @@ Init_ossl_cipher(void) rb_define_method(cCipher, "block_size", ossl_cipher_block_size, 0); + rb_define_method(cCipher, "padding=", ossl_cipher_set_padding, 1); + } /* Init_ossl_cipher */ |