Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue with contains() #110

Open
panva opened this issue Mar 26, 2019 · 6 comments
Open

issue with contains() #110

panva opened this issue Mar 26, 2019 · 6 comments

Comments

@panva
Copy link

panva commented Mar 26, 2019

Assume the following

const asn = require('asn1.js')

const Bar = asn.define('Bar', function () {
  this.octstr().contains().obj(
    this.key('bar').octstr()
  )
})

const Foo = asn.define('Foo', function () {
  this.seq().obj(
    this.key('foo').use(Bar)
  )
})

Foo.encode({
  foo: { bar: Buffer.from('bar') }
}, 'der').toString('base64')

The output i'm expecting is

<Buffer 30 07 04 05 04 03 62 61 72>
              ^^ ✅

But i'm instead getting

<Buffer 30 07 24 05 04 03 62 61 72>
              ^^ ❌

I went back and forth with the definitions and couldn't get this to be what i need. I can see very little examples around this.

@felix / @indutny, this was added in #59, i could very much use your hand in figuring out if this is a problem with the feature or my definition.

@felix
Copy link
Contributor

felix commented Mar 27, 2019

I have not worked with ASN.1 for a while now but off the top of my head is that the difference between BER and DER, DER should prefer constructed definite-length encoding. So perhaps your expectation is actually BER and it is producing DER. I may well be wrong!

@mattcollier
Copy link

@panva encountering the exact same issue here: https://github.com/digitalbazaar/crypto-ld/compare/node-12#diff-19ce09a32f875322daf2628d6aceb210R31

Any luck finding a solution?

@panva
Copy link
Author

panva commented Jul 13, 2019

@felix
Copy link
Contributor

felix commented Jul 18, 2019

I suppose the first step would be to create the simplest test using contains that generates the incorrect sequence.

@panva
Copy link
Author

panva commented Jul 18, 2019

@felix is the one in the description not simple enough?

@felix
Copy link
Contributor

felix commented Jul 21, 2019

It is, my apologies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants