asn1js icon indicating copy to clipboard operation
asn1js copied to clipboard

ASN1.toObject

Open microshine opened this issue 9 years ago • 5 comments

Propose to add new functionality. Add feature allows to convert ASN structure in Javascript object using given schema.

Extension = {
    type: "SEQUENCE",
    value: {
        typeId: {type: "OBJECT ITDENTIFIER"},
        value: {type: "ANY"}
    }
}

var asn = ANS1.decode(data);
var o = asn.toObject(Extension);

// structure of 'o'
{
    typeId: "1.2.3.4.5.6",
    value: [18, 3, 1, 1, 0]
}

microshine avatar Apr 20 '15 05:04 microshine

Sorry, I don't understand what is happening there… what are type and typeId and value used for exactly? How is the parameter formatted?

lapo-luchini avatar Apr 22 '15 14:04 lapo-luchini

ASN1 structure SEQUENCE (2 elem) OBJECT IDENTIFIER 2.5.29.37   OCTET STRING (1 elem) SEQUENCE (2 elem) OBJECT IDENTIFIER 1.3.6.1.5.5.7.3.2   OBJECT IDENTIFIER 1.3.6.1.5.5.7.3.4 This is data of X509 Extension (RFC 5280)

Extension ::= SEQUENCE { extnID OBJECT IDENTIFIER, critical BOOLEAN DEFAULT FALSE, extnValue OCTET STRING -- contains the DER encoding of an ASN.1 value -- corresponding to the extension type identified -- by extnID } JavaScript schema

schemas.Extension = {     type: "SEQUENCE",    // ASN1 type of element     value: {                           // ASN1 element value or structure         extnID: {             type: "OBJECT IDENTIFIER" // it's not got a prop value because it's a simple ASN1 type         },         critical:{              type: "BOOLEAN",              default: false,              optional: true // because critical has  'default '         },         extnValue: {             type: "OCTET STRING"         }     } }

JavaScrip code

asn.toObject(schemas.Extension)

return value of function is

{     extnID: "2.5.29.37",     crytical: false,     extnValue: Uint8Array[...] }

Среда, 22 апреля 2015, 7:06 -07:00 от Lapo Luchini [email protected]:

Sorry, I don't understand what is happening there… what are type and typeId and value used for exactly? How is the parameter formatted? — Reply to this email directly or view it on GitHub .

[email protected]

microshine avatar Apr 22 '15 14:04 microshine

Ah ok, you mean parsing an ASN.1 format definition file and decoding using named structures instead of anonymous ASN.1 structures? That's not so fast to do and isn't a feature I need, so I don't think I will implement that anytime soon. But as you say it can be done as a post-processing on the current output from ASN1.decode(array), so if anyone feels like implementing it, I would certainly consider pull requests.

lapo-luchini avatar Apr 22 '15 15:04 lapo-luchini

I wrote simple ASN1Schema JavaScript code. It has got only one method 'get'. I sent source code of my library to your email. Can you examinate it and tell me ypur oppinin. If you'd like it I can help you to write ASN1.toObject method.

Среда, 22 апреля 2015, 8:12 -07:00 от Lapo Luchini [email protected]:

Ah ok, you mean parsing an ASN.1 format definition file and decoding using named structures instead of anonymous ASN.1 structures? That's not so fast to do and isn't a feature I need, so I don't think I will implement that anytime soon. But as you say it can be done as a post-processing on the current output from ASN1.decode(array), so if anyone feels like implementing it, I would certainly consider pull requests. — Reply to this email directly or view it on GitHub . [email protected]

microshine avatar Apr 22 '15 21:04 microshine

@microshine I'm so sorry! This was good stuff, but at the time I was too stressed to think about it and then I totally forgot about this issue. :(

I started coding this feature myself a few days ago, using a different approach (parsing BNF definitions directly out of RFC sources).

I'll work on integrating that with the parser next.

lapo-luchini avatar Dec 12 '21 10:12 lapo-luchini