[Pkg-javascript-commits] [node-keygrip] 13/68: updated README with .index

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 61d33dada58520ea7ad35e726c6cccebc1394a73
Author: Jed Schmidt <tr at nslator.jp>
Date:   Fri Feb 25 23:28:24 2011 +0900

    updated README with .index
---
 README.md | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/README.md b/README.md
index 327a62d..eeea468 100644
--- a/README.md
+++ b/README.md
@@ -45,14 +45,14 @@ The idea is that if the index returned is greater than `0`, the data should be r
 
     // ./test.js
     var assert = require( "assert" )
-      , keygrip = require( "keygrip" )
+      , Keygrip = require( "keygrip" )
       , keylist, keys, hash, index
     
     // keygrip takes an array of keys, but if none exist,
     // it uses the defaults created during npm installation.
     // (but it'll will warn you)
     console.log( "Ignore this message:" )
-    keys = keygrip( /* empty list */ )
+    keys = new Keygrip( /* empty list */ )
     
     // .sign returns the hash for the first key
     // all hashes are SHA1 HMACs in url-safe base64
@@ -62,14 +62,18 @@ The idea is that if the index returned is greater than `0`, the data should be r
     // but we're going to use our list.
     // (note that the 'new' operator is optional)
     keylist = [ "SEKRIT3", "SEKRIT2", "SEKRIT1" ]
-    keys = keygrip( keylist )
+    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
@@ -77,10 +81,10 @@ The idea is that if the index returned is greater than `0`, the data should be r
     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" )
-    
+    hash = keys.sign( "bieberschnitzel" ) 
+
 ## TODO
 
 * Rewrite the `cookie` library to use `Keygrip`

-- 
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