summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/openssl/lib/openssl/x509.rb9
-rw-r--r--ext/openssl/ossl_cipher.c17
-rw-r--r--ext/openssl/ossl_cipher.h1
-rw-r--r--ext/openssl/ossl_digest.c17
-rw-r--r--ext/openssl/ossl_digest.h1
5 files changed, 44 insertions, 1 deletions
diff --git a/ext/openssl/lib/openssl/x509.rb b/ext/openssl/lib/openssl/x509.rb
index f7df597acb..8efe3701c8 100644
--- a/ext/openssl/lib/openssl/x509.rb
+++ b/ext/openssl/lib/openssl/x509.rb
@@ -88,7 +88,7 @@ module OpenSSL
end # Extension
class Attribute
- def Attribute::new(arg)
+ def self.new(arg)
type = arg.class
while type
method = "new_from_#{type.name.downcase}".intern
@@ -128,5 +128,12 @@ module OpenSSL
end
end # Attribute
+ class Name
+ def self.parse(str)
+ ary = str.scan(/\s*([^\/,]+)\s*/).collect{|i| i[0].split("=") }
+ self.new(ary)
+ end
+ end # Name
+
end # X509
end # OpenSSL
diff --git a/ext/openssl/ossl_cipher.c b/ext/openssl/ossl_cipher.c
index 3d63a2a038..02e3dcd488 100644
--- a/ext/openssl/ossl_cipher.c
+++ b/ext/openssl/ossl_cipher.c
@@ -30,6 +30,8 @@ VALUE mCipher;
VALUE cCipher;
VALUE eCipherError;
+static VALUE ossl_cipher_alloc(VALUE klass);
+
/*
* PUBLIC
*/
@@ -43,6 +45,21 @@ GetCipherPtr(VALUE obj)
return EVP_CIPHER_CTX_cipher(ctx);
}
+VALUE
+ossl_cipher_new(const EVP_CIPHER *cipher)
+{
+ VALUE ret;
+ EVP_CIPHER_CTX *ctx;
+
+ ret = ossl_cipher_alloc(cCipher);
+ GetCipher(ret, ctx);
+ EVP_CIPHER_CTX_init(ctx);
+ if (EVP_CipherInit(ctx, cipher, NULL, NULL, -1) != 1)
+ ossl_raise(eCipherError, NULL);
+
+ return ret;
+}
+
/*
* PRIVATE
*/
diff --git a/ext/openssl/ossl_cipher.h b/ext/openssl/ossl_cipher.h
index 4dcbd4fd89..63c7a875e8 100644
--- a/ext/openssl/ossl_cipher.h
+++ b/ext/openssl/ossl_cipher.h
@@ -16,6 +16,7 @@ extern VALUE cCipher;
extern VALUE eCipherError;
const EVP_CIPHER *GetCipherPtr(VALUE);
+VALUE ossl_cipher_new(const EVP_CIPHER *);
void Init_ossl_cipher(void);
#endif /* _OSSL_CIPHER_H_ */
diff --git a/ext/openssl/ossl_digest.c b/ext/openssl/ossl_digest.c
index e04b145889..8511eccf4e 100644
--- a/ext/openssl/ossl_digest.c
+++ b/ext/openssl/ossl_digest.c
@@ -28,6 +28,8 @@ VALUE mDigest;
VALUE cDigest;
VALUE eDigestError;
+static VALUE ossl_digest_alloc(VALUE klass);
+
/*
* Public
*/
@@ -41,6 +43,20 @@ GetDigestPtr(VALUE obj)
return EVP_MD_CTX_md(ctx); /*== ctx->digest*/
}
+VALUE
+ossl_digest_new(const EVP_MD *md)
+{
+ VALUE ret;
+ EVP_MD_CTX *ctx;
+
+ ret = ossl_digest_alloc(cDigest);
+ GetDigest(ret, ctx);
+ EVP_MD_CTX_init(ctx);
+ EVP_DigestInit(ctx, md);
+
+ return ret;
+}
+
/*
* Private
*/
@@ -79,6 +95,7 @@ ossl_digest_initialize(int argc, VALUE *argv, VALUE self)
if (!md) {
ossl_raise(rb_eRuntimeError, "Unsupported digest algorithm (%s).", name);
}
+ EVP_MD_CTX_init(ctx);
EVP_DigestInit(ctx, md);
if (!NIL_P(data)) return ossl_digest_update(self, data);
diff --git a/ext/openssl/ossl_digest.h b/ext/openssl/ossl_digest.h
index 5aa1c42f05..8a1f7964f2 100644
--- a/ext/openssl/ossl_digest.h
+++ b/ext/openssl/ossl_digest.h
@@ -16,6 +16,7 @@ extern VALUE cDigest;
extern VALUE eDigestError;
const EVP_MD *GetDigestPtr(VALUE);
+VALUE ossl_digest_new(const EVP_MD *);
void Init_ossl_digest(void);
#endif /* _OSSL_DIGEST_H_ */