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

ASN1.toObject #13

Open
microshine opened this issue Apr 20, 2015 · 5 comments
Open

ASN1.toObject #13

microshine opened this issue Apr 20, 2015 · 5 comments

Comments

@microshine
Copy link

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]
}
@lapo-luchini
Copy link
Owner

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

@microshine
Copy link
Author

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 notifications@github.com:

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 .

microshine@mail.ru

@lapo-luchini
Copy link
Owner

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.

@microshine
Copy link
Author

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 notifications@github.com:

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 .
microshine@mail.ru

@lapo-luchini
Copy link
Owner

@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.

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
@lapo-luchini @microshine and others