Skip to content

Commit

Permalink
Add hash option to getFingerprint function
Browse files Browse the repository at this point in the history
`getFingerprint(certificate, [hash,] callback)`
  • Loading branch information
Josef Fröhle committed Feb 24, 2015
1 parent 9f16c23 commit d8556de
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,14 @@ Where

### Get fingerprint

Use `getFingerprint` to get the SHA1 fingerprint for a certificate
Use `getFingerprint` to get the default SHA1 fingerprint for a certificate

pem.getFingerprint(certificate, callback)
pem.getFingerprint(certificate, [hash,] callback)

Where

* **certificate** is a PEM encoded certificate
* **hash** is a hash function to use (either `md5`, `sha1` or `sha256`, defaults to `sha1`)
* **callback** is a callback function with an error object and `{fingerprint}`

### Get modulus
Expand Down
11 changes: 10 additions & 1 deletion lib/pem.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,21 @@ function config(options) {
* @param {String} PEM encoded certificate
* @param {Function} callback Callback function with an error object and {fingerprint}
*/
function getFingerprint(certificate, callback) {
function getFingerprint(certificate, hash, callback) {

if (!callback && typeof hash === 'function') {
callback = hash;
hash = undefined;
}

hash = hash || 'sha1';

var params = ['x509',
'-in',
'--TMPFILE--',
'-fingerprint',
'-noout'
'-'+hash
];

spawnWrapper(params, certificate, function(err, code, stdout) {
Expand Down

0 comments on commit d8556de

Please sign in to comment.