couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject [23/50] git commit: Use public_key-0.8 API (R14B).
Date Fri, 17 Jan 2014 22:57:27 GMT
Use public_key-0.8 API (R14B).


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/2559e8bb
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/2559e8bb
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/2559e8bb

Branch: refs/heads/import
Commit: 2559e8bbf4be816c545a5dd467225a20e0c9dd06
Parents: 546d0ee
Author: Tim Fletcher <mail@tfletcher.com>
Authored: Fri Nov 26 15:31:52 2010 +0000
Committer: Tim Fletcher <mail@tfletcher.com>
Committed: Fri Nov 26 15:31:52 2010 +0000

----------------------------------------------------------------------
 src/oauth_rsa_sha1.erl | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/2559e8bb/src/oauth_rsa_sha1.erl
----------------------------------------------------------------------
diff --git a/src/oauth_rsa_sha1.erl b/src/oauth_rsa_sha1.erl
index a7b570c..99bd926 100644
--- a/src/oauth_rsa_sha1.erl
+++ b/src/oauth_rsa_sha1.erl
@@ -5,25 +5,26 @@
 -include_lib("public_key/include/public_key.hrl").
 
 signature(BaseString, PrivateKeyPath) ->
-  {ok, [Info]} = public_key:pem_to_der(PrivateKeyPath),
-  {ok, PrivateKey} = public_key:decode_private_key(Info),
-  base64:encode_to_string(public_key:sign(list_to_binary(BaseString), PrivateKey)).
+  {ok, Contents} = file:read_file(PrivateKeyPath),
+  [Info] = public_key:pem_decode(Contents),
+  PrivateKey = public_key:pem_entry_decode(Info),
+  base64:encode_to_string(public_key:sign(list_to_binary(BaseString), sha, PrivateKey)).
 
-verify(Signature, BaseString, PublicKey) ->
-  public_key:verify_signature(to_binary(BaseString), sha, base64:decode(Signature), public_key(PublicKey)).
+verify(Signature, BaseString, Cert) ->
+  public_key:verify(to_binary(BaseString), sha, base64:decode(Signature), pkey(Cert)).
 
 to_binary(Term) when is_list(Term) ->
   list_to_binary(Term);
 to_binary(Term) when is_binary(Term) ->
   Term.
 
-public_key(Path) when is_list(Path) ->
-  {ok, [{cert, DerCert, not_encrypted}]} = public_key:pem_to_der(Path),
-  {ok, Cert} = public_key:pkix_decode_cert(DerCert, otp),
-  public_key(Cert);
-public_key(#'OTPCertificate'{tbsCertificate=Cert}) ->
-  public_key(Cert);
-public_key(#'OTPTBSCertificate'{subjectPublicKeyInfo=Info}) ->
-  public_key(Info);
-public_key(#'OTPSubjectPublicKeyInfo'{subjectPublicKey=Key}) ->
+pkey(Path) when is_list(Path) ->
+  {ok, Contents} = file:read_file(Path),
+  [{'Certificate', DerCert, not_encrypted}] = public_key:pem_decode(Contents),
+  pkey(public_key:pkix_decode_cert(DerCert, otp));
+pkey(#'OTPCertificate'{tbsCertificate=Cert}) ->
+  pkey(Cert);
+pkey(#'OTPTBSCertificate'{subjectPublicKeyInfo=Info}) ->
+  pkey(Info);
+pkey(#'OTPSubjectPublicKeyInfo'{subjectPublicKey=Key}) ->
   Key.


Mime
View raw message