better state management

This commit is contained in:
AJ ONeal 2015-12-15 12:42:56 +00:00
parent 89ef517338
commit f6a049d92a
1 changed files with 13 additions and 0 deletions

View File

@ -104,6 +104,11 @@ Acme.prototype.post=function(url, body, cb) {
function registerNewAccount(state, options, cb) {
var state = {};
if (!options.accountPrivateKeyPem) {
return handleErr(new Error("options.accountPrivateKeyPem must be an ascii private key pem"));
}
if (!options.agreeToTerms) {
cb(new Error("options.agreeToTerms must be function (tosUrl, fn => (err, true))"));
return;
@ -117,6 +122,10 @@ function registerNewAccount(state, options, cb) {
return;
}
state.accountKeyPem=options.accountPrivateKeyPem;
state.accountKeyPair=cryptoUtil.importPemPrivateKey(state.accountKeyPEM);
state.acme=new Acme(state.accountKeyPair);
register();
function register() {
@ -216,7 +225,11 @@ function getCert(options, cb) {
if (!options.removeChallenge) {
return handleErr(new Error("options.removeChallenge must be function(hostname, challengeKey, done) {}"));
}
if (!(options.domains && options.domains.length)) {
return handleErr(new Error("options.domains must be an array of domains such as ['example.com', 'www.example.com']"));
}
state.domains = options.domains.slice(0); // copy array
try {
state.accountKeyPem=options.accountPrivateKeyPem;
state.accountKeyPair=cryptoUtil.importPemPrivateKey(state.accountKeyPEM);