[Pkg-javascript-commits] [node-keygrip] 03/68: use test.js for README usage example.

Andrew Kelley andrewrk-guest at moszumanska.debian.org
Fri Jun 27 22:13:23 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 78c41a422fc3f9461e54754baddbc1daeb621f4a
Author: Jed Schmidt <tr at nslator.jp>
Date:   Fri Feb 25 15:33:25 2011 +0900

    use test.js for README usage example.
---
 README.md | 30 ++++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)

diff --git a/README.md b/README.md
index 6fb24ac..6f98f59 100644
--- a/README.md
+++ b/README.md
@@ -13,19 +13,33 @@ keygrip is a [node.js](http://nodejs.org/) module for signing and verifying data
     
 ## Usage
 
-    secrets = [ "SEKRIT3", "SEKRIT2", "SEKRIT1" ]
-    keys = require( "./" )( secrets )
+    // from ./test.js
+    var assert = require( "assert" )
+      , secrets = [ "SEKRIT3", "SEKRIT2", "SEKRIT1" ]
+      , keys = require( "./" )( secrets )
+      , hash, index
     
-    hash = keys.sign( "bieberschnitzel" )   // => tGdm98qasPSCUpW9ksobxcIjW1E
+    // .sign returns the hash for the first key
+    // all hashes are SHA1 HMACs in url-safe base64
+    hash = keys.sign( "bieberschnitzel" )
+    assert.equal( hash, "4O9Lm0qQPd7_pViJBPKA_8jYwb8" )
     
-    keys.verify( "bieberschnitzel", hash )  // => 0 (1st key matched)
-    keys.verify( "bieberschnitzel", "o_O" ) // => -1 (not matched)
+    // .verify returns the index of the first matching key
+    index = keys.verify( "bieberschnitzel", hash )
+    assert.equal( index, 0 )
     
-    secrets.unshift( "SEKRIT4" )            // rotate a new key in
-    secrets.pop()                           // rotate the oldest key out
+    index = keys.verify( "bieberschnitzel", "o_O" )
+    assert.equal( index, -1 )
     
-    keys.verify( "bieberschnitzel", hash )  // => 1 (2nd key matched, time to re-sign)
+    // rotate a new key in, and an old key out
+    secrets.unshift( "SEKRIT4" )
+    secrets.pop()
     
+    // if index > 0, it's time to re-sign
+    index = keys.verify( "bieberschnitzel", hash )
+    assert.equal( index, 1 )
+    hash = keys.sign( "bieberschnitzel" )
+
 Copyright
 ---------
 

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