Skip to content

Commit

Permalink
jshinted code
Browse files Browse the repository at this point in the history
  • Loading branch information
Andris Reinman committed Jun 24, 2012
1 parent 6124955 commit bacb2ec
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 34 deletions.
59 changes: 30 additions & 29 deletions lib/pem.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function createCSR(options, callback){
var response = {
csr: data,
clientKey: options.clientKey
}
};
return callback(null, response);

});
Expand Down Expand Up @@ -124,15 +124,15 @@ function createCertificate(options, callback){
clientKey: options.clientKey,
certificate: data,
serviceKey: options.serviceKey
}
};
return callback(null, response);
});
}

function getPublicKey(certificate, callback){
if(!callback && typeof options == "function"){
callback = options;
options = undefined;
if(!callback && typeof certificate == "function"){
callback = certificate;
certificate = undefined;
}

certificate = (certificate || "").toString();
Expand All @@ -147,15 +147,15 @@ function getPublicKey(certificate, callback){
"-noout"];
}else if(certificate.match(/BEGIN RSA PRIVATE KEY/)){
params = ["rsa",
"-in",
"/dev/stdin",
"-pubout"];
"-in",
"/dev/stdin",
"-pubout"];
}else{
params = ["x509",
"-in",
"/dev/stdin",
"-pubkey",
"-noout"];
"-in",
"/dev/stdin",
"-pubkey",
"-noout"];
}

execOpenSSL(params, "PUBLIC KEY", certificate, function(error, key){
Expand All @@ -167,9 +167,9 @@ function getPublicKey(certificate, callback){
}

function readCertificateInfo(certificate, callback){
if(!callback && typeof options == "function"){
callback = options;
options = undefined;
if(!callback && typeof certificate == "function"){
callback = certificate;
certificate = undefined;
}

certificate = (certificate || "").toString();
Expand Down Expand Up @@ -271,7 +271,17 @@ function generateCSRSubject(options){
function execOpenSSL(params, searchStr, stdin, callback){
var openssl = spawn("openssl", params),
stdout = "",
stderr = "";
stderr = "",
pushToStdin = function(){
var data = stdin.shift();

if(data){
openssl.stdin.write(data + "\n");
if(!stdin.length){
openssl.stdin.end();
}
}
};

if(!callback && typeof stdin == "function"){
callback = stdin;
Expand Down Expand Up @@ -301,12 +311,13 @@ function execOpenSSL(params, searchStr, stdin, callback){
openssl.on('exit', function (code) {
var start, end;

stdout = new Buffer(stdout, "binary").toString("utf-8");
stderr = new Buffer(stderr, "binary").toString("utf-8");

if(code){
return callback(new Error("Invalid openssl exit code "+code));
return callback(new Error("Invalid openssl exit code "+code+"\nSTDOUT:\n"+stdout+"\nSTDERR:\n"+stderr));
}

stdout = new Buffer(stdout, "binary").toString("utf-8");

if((start = stdout.match(new RegExp("\\-+BEGIN "+searchStr+"\\-+$", "m")))){
start = start.index;
}else{
Expand All @@ -326,14 +337,4 @@ function execOpenSSL(params, searchStr, stdin, callback){
}
});

function pushToStdin(){
var data = stdin.shift();

if(data){
openssl.stdin.write(data + "\n");
if(!stdin.length){
openssl.stdin.end();
}
}
}
}
10 changes: 5 additions & 5 deletions test/pem.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ exports["General Tests"] = {
organization: '',
organizationUnit: '',
commonName: 'localhost',
emailAddress: '' })
emailAddress: '' });
test.done();
});
});
Expand All @@ -132,7 +132,7 @@ exports["General Tests"] = {

pem.readCertificateInfo(csr, function(error, data){
test.ifError(error);
test.deepEqual(data, certInfo)
test.deepEqual(data, certInfo);
test.done();
});
});
Expand All @@ -152,7 +152,7 @@ exports["General Tests"] = {
organization: '',
organizationUnit: '',
commonName: 'localhost',
emailAddress: '' })
emailAddress: '' });
test.done();
});
});
Expand All @@ -172,7 +172,7 @@ exports["General Tests"] = {

pem.readCertificateInfo(certificate, function(error, data){
test.ifError(error);
test.deepEqual(data, certInfo)
test.deepEqual(data, certInfo);
test.done();
});
});
Expand Down Expand Up @@ -237,4 +237,4 @@ exports["General Tests"] = {

});
}
}
};

0 comments on commit bacb2ec

Please sign in to comment.