[Pkg-javascript-commits] [node-keygrip] 16/68: changed default keys to .json, made them optional

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 4825ebd4b06e3286eda829ee1ccadd206fd33c7a
Author: Jed Schmidt <tr at nslator.jp>
Date:   Sat Feb 26 21:47:08 2011 +0900

    changed default keys to .json, made them optional
---
 lib/defaultKeys.json |  1 +
 lib/keygrip.js       | 15 ++++++++++++---
 scripts/install.js   |  4 ++--
 3 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/lib/defaultKeys.json b/lib/defaultKeys.json
new file mode 100644
index 0000000..a40014e
--- /dev/null
+++ b/lib/defaultKeys.json
@@ -0,0 +1 @@
+["9d28a2aba7f42d0db53c3a3fbf817f6c"]
\ No newline at end of file
diff --git a/lib/keygrip.js b/lib/keygrip.js
index e674f88..12db11e 100644
--- a/lib/keygrip.js
+++ b/lib/keygrip.js
@@ -1,12 +1,21 @@
 crypto = require( "crypto" )
-defaults = require( "./defaultKeys" )
+path = require( "path" )
+fs = require( "fs" )
+
+defaults = path.existsSync( "lib/defaultKeys.json" )
+  ? JSON.parse( fs.readFileSync( "lib/defaultKeys.json" ) )
+  : undefined
 
 function Keygrip( keys ) {
   if ( !( this instanceof Keygrip ) ) return new Keygrip( keys )
   
   if ( !keys || !( 0 in keys ) ) {
-    console.warn( "No keys specified, using defaults instead." )
-    keys = defaults
+    if ( defaults ) {
+      console.warn( "No keys specified, using defaults instead." )
+      keys = defaults
+    }
+    
+    else throw "Keys must be provided or default keys must exist."
   }
   
   function sign( data, key ) {
diff --git a/scripts/install.js b/scripts/install.js
index 7eaeaa7..4ab4780 100644
--- a/scripts/install.js
+++ b/scripts/install.js
@@ -1,5 +1,5 @@
-require( "fs" ).writeFileSync( "./lib/defaultKeys.js",
-  "module.exports = " + JSON.stringify([
+require( "fs" ).writeFileSync( "./lib/defaultKeys.json",
+  JSON.stringify([
     Array( 33 ).join( "x" ).replace( /x/g, function() {
       return ( Math.random()*16|0 ).toString(16)
     })

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