Skip to content

Commit

Permalink
Merge pull request #5 from omsmith/document-short-vs-long-length
Browse files Browse the repository at this point in the history
(chore) explain short length vs long form
  • Loading branch information
omsmith committed Jun 13, 2015
2 parents 63715fd + 13a25e4 commit 5423b70
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/ecdsa-sig-formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,21 @@ function joseToDer(signature, alg) {

var rsBytes = 1 + 1 + r.length + 1 + 1 + s.length;

var oneByteLength = rsBytes < MAX_OCTET;
var shortLength = rsBytes < MAX_OCTET;

signature = new Buffer((oneByteLength ? 2 : 3) + rsBytes);
signature = new Buffer((shortLength ? 2 : 3) + rsBytes);

var offset = 0;
signature[offset++] = ENCODED_TAG_SEQ;
if (oneByteLength) {
if (shortLength) {
// Bit 8 has value "0"
// bits 7-1 give the length.
signature[offset++] = rsBytes;
} else {
// Bit 8 of first octet has value "1"
// bits 7-1 give the number of additional length octets.
signature[offset++] = MAX_OCTET | 1;
// length, base 256
signature[offset++] = rsBytes & 0xff;
}
signature[offset++] = ENCODED_TAG_INT;
Expand Down

0 comments on commit 5423b70

Please sign in to comment.