Closed Caracasa closed 2 years ago
Have you seen our another package @peculiar/asn1-schema
? It's based on ASN1.js and allows using TypeScript decorators for schema declaration.
And schema declaration could see like this
/**
* ```
* Definition DEFINITIONS AUTOMATIC TAGS ::=
* BEGIN
*
* Seq ::= SEQUENCE {
* oid [1] OBJECT IDENTIFIER,
* ...
* }
*
* END
* ```
*/
@AsnType()
export class MysSeq {
@AsnProp({ type: AsnPropTypes.ObjecIdentifier, context: 1, implicit: true })
public oid: string;
}
I have now. A very sleek and easy to use approach to the topic "asn1-schema" after setting up the support for the experimental decorators. We will make good use of it.
@AsnType({type: AsnTypeTypes.Sequence})
export class TrapSequence {
@AsnProp({ type: AsnPropTypes.ObjecIdentifier, context: 1, implicit: true })
public oid: string;
}
[...]
}
@Caracasa If you are declaring an RFC ASN.1 schema, you could make a PR of your schema to the https://github.com/PeculiarVentures/asn1-schema mono repo and allow NodeJS community to use it.
It is an application-specific schema for storing structured sensor/log data.
With an ASN1 definition using IMPLICIT tagging I need a push in the right direction how to decode an ObjectIdentifier.
How would I construct the sequence object for decoding (of the oid) in that case? I read the example in #45 but do not understand how to adapt it to my usecase.
To be honest at the moment I manually iterate over the sequence and match ids to use primitive objects with the valueBlocks. For asn1js.ObjectIdentifier I failed to instantiate the object from the raw arraybuffer.