indutny / asn1.js

ASN.1 Decoder/Encoder/DSL
MIT License
181 stars 64 forks source link

der: support negative integers #114

Open jablko opened 5 years ago

jablko commented 5 years ago

Before

const INTEGER = asn1.define('INTEGER', function() {
  this.int();
});
console.log(INTEGER.decode(INTEGER.encode(-1))); // Error: non-byte EncoderBuffer value at: (shallow)

After

console.log(INTEGER.decode(INTEGER.encode(-1))); // <BN: -1>
console.log(INTEGER.decode(INTEGER.encode(-0x81))); // <BN: -81>