[Pkg-javascript-commits] [node-keygrip] 11/68: renamed .verify to .index, added verify

Andrew Kelley andrewrk-guest at moszumanska.debian.org
Fri Jun 27 22:13:24 UTC 2014


This is an automated email from the git hooks/post-receive script.

andrewrk-guest pushed a commit to branch master
in repository node-keygrip.

commit 815c114fadcd1ce5880b1ae8428a9cad60a1ad1b
Author: Jed Schmidt <tr at nslator.jp>
Date:   Fri Feb 25 23:26:14 2011 +0900

    renamed .verify to .index, added verify
---
 lib/keygrip.js |  4 ++++
 test.js        | 12 ++++++++----
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/lib/keygrip.js b/lib/keygrip.js
index afcb455..e674f88 100644
--- a/lib/keygrip.js
+++ b/lib/keygrip.js
@@ -21,6 +21,10 @@ function Keygrip( keys ) {
   this.sign = function( data ){ return sign( data, keys[ 0 ] ) }
 
   this.verify = function( data, digest ) {
+    return this.index( data, digest ) > -1
+  }
+
+  this.index = function( data, digest ) {
     for ( var i = 0, l = keys.length; i < l; i++ ) {
       if ( digest === sign( data, keys[ i ] ) ) return i
     }
diff --git a/test.js b/test.js
index b22dc49..ec2969f 100644
--- a/test.js
+++ b/test.js
@@ -20,11 +20,15 @@ keylist = [ "SEKRIT3", "SEKRIT2", "SEKRIT1" ]
 keys = Keygrip( keylist )
 hash = keys.sign( "bieberschnitzel" )
 
-// .verify returns the index of the first matching key
-index = keys.verify( "bieberschnitzel", hash )
+// .index returns the index of the first matching key
+index = keys.index( "bieberschnitzel", hash )
 assert.equal( index, 0 )
 
-index = keys.verify( "bieberschnitzel", "o_O" )
+// .verify returns the a boolean indicating a matched key
+matched = keys.verify( "bieberschnitzel", hash )
+assert.ok( matched )
+
+index = keys.index( "bieberschnitzel", "o_O" )
 assert.equal( index, -1 )
 
 // rotate a new key in, and an old key out
@@ -32,6 +36,6 @@ keylist.unshift( "SEKRIT4" )
 keylist.pop()
 
 // if index > 0, it's time to re-sign
-index = keys.verify( "bieberschnitzel", hash )
+index = keys.index( "bieberschnitzel", hash )
 assert.equal( index, 1 )
 hash = keys.sign( "bieberschnitzel" )
\ No newline at end of file

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-keygrip.git



More information about the Pkg-javascript-commits mailing list