mouse07410 / asn1c

The ASN.1 Compiler
http://lionet.info/asn1c/
BSD 2-Clause "Simplified" License
101 stars 73 forks source link

parse parameterized Type failed #194

Closed BlaizeLei closed 4 months ago

BlaizeLei commented 4 months ago

I use asn1c to generate C code from an asn file, but I got such warning and errors:

FATAL: Type ScmsPdu-Scoped expects specialization from ScmsPdu-Scoped at line 30 in test.asn
FATAL: Cannot find type "<Type>" in constraints at line 34 in test.asn
FATAL: Type ScmsPdu-Scoped expects specialization from ScmsPdu-Scoped at line 35 in test.asn
FATAL: Cannot find type "<Type>" in constraints at line 40 in test.asn
FATAL: Type ScmsPdu-Scoped expects specialization from ScmsPdu-Scoped at line 30 in test.asn
FATAL: Cannot find type "<Type>" in constraints at line 34 in test.asn
FATAL: Type ScmsPdu-Scoped expects specialization from ScmsPdu-Scoped at line 35 in test.asn
FATAL: Cannot find type "<Type>" in constraints at line 40 in test.asn
FATAL: Type ScmsPdu-Scoped expects specialization from ScmsPdu-Scoped at line 30 in test.asn
FATAL: Cannot find type "<Type>" in constraints at line 34 in test.asn
FATAL: Type ScmsPdu-Scoped expects specialization from ScmsPdu-Scoped at line 35 in test.asn
FATAL: Cannot find type "<Type>" in constraints at line 40 in test.asn

And these is my test.asn content:

World-Schema DEFINITIONS AUTOMATIC TAGS ::= BEGIN

Uint8 ::= INTEGER (0..255)                  -- (hex)

RaAcaCertRequest ::= OCTET STRING(SIZE(32))
AcaRaCertResponse ::= OCTET STRING(SIZE(48))

AcaRaInterfacePdu ::= CHOICE {
  raAcaCertRequest   RaAcaCertRequest,
  acaRaCertResponse  AcaRaCertResponse,
  ...
}

ScmsPdu ::= SEQUENCE {
  version  Uint8 (1),
  content  CHOICE {
    aca-ra  AcaRaInterfacePdu,
    ...
  }
}

ScmsPdu-Scoped {Pdu} ::= ScmsPdu (WITH COMPONENTS {
  ...,
  content (CONSTRAINED BY {
    Pdu
  })
})

ScopedCertificateRequest ::= ScmsPdu (
  ScmsPdu-Scoped {
    AcaRaInterfacePdu (WITH COMPONENTS {
      raAcaCertRequest
    })
  }|
  ScmsPdu-Scoped {
    AcaRaInterfacePdu (WITH COMPONENTS {
      acaRaCertResponse  
    })
  }
)

END

These asn can be parse well by other asn to c compiler, such as ossasn1c and eclipse asn compiler.

Thank you very much and look forward to your reply!

mouse07410 commented 4 months ago

It seems that the ASN.1 files you're using include new(er) and more complicated language features, that this Open Source compiler is unable to handle. OSS Nokalva compiler is good (no arguments here!), but it costs good amount of money.

What is "eclipse asn compiler"? Could you please provide a URL to it?

I don't have enough competence (let alone time) to enhance asn1c to add support for those capabilities.

Sorry for not being more helpful.

BlaizeLei commented 4 months ago

Thank you very much for your reply.

I have the same question as another person, and I referenced his question link: [https://github.com/vlm/asn1c/issues/400].

The link to eclipse asn compiler may be this one :https://www.eclipse.org/downloads/.

mouse07410 commented 4 months ago

Sorry, both "working" compilers you're referring to, cost money. The 2nd one is available as an Eclipse plugin, but it's by no means free (also, it's vendor doesn't list the price on the web site).

Add I said, I don't think I can help here - this problem is the result of authors of those ASN.1 files using features they really (IMHO) shouldn't've. Unless somebody provides a PR here, extending the capabilities of asn1c, that kind of files (using "crazy" language features) won't be supported.

If you can afford Nokalva or ASN(name of the company, not the language here) compiler - by all means keep using them, add they will always be richer in capabilities compared to this one.

BlaizeLei commented 4 months ago

Let's take a different approach. The main error now is that the call syntax of ScopedCertificateRequest to ScmsPdu-Scoped cannot be recognized. Can we achieve the same effect by modifying the ASN syntax below? It is to modify it to a syntax that the compiler can recognize and has the same meaning.

ScopedCertificateRequest ::= ScmsPdu (
  ScmsPdu-Scoped {
    AcaRaInterfacePdu (WITH COMPONENTS {
      raAcaCertRequest
    })
  }|
  ScmsPdu-Scoped {
    AcaRaInterfacePdu (WITH COMPONENTS {
      acaRaCertResponse  
    })
  }
)
mouse07410 commented 4 months ago

Can we achieve the same effect by modifying the ASN syntax below? It is to modify it to a syntax that the compiler can recognize and has the same meaning.

I cannot answer this question - but my feeling is that what you're proposing (aka, modifying ASN.1 files to make them less dependent on the "modern" language features) is the only way to get ASN.1 files(s) in question parsed/understood by asn1c. And if that doesn't work - the only other option remaining would be using OSS Nokalva or similar.

Update

For those interested - here's the OBJ-SYS price list: https://obj-sys.com/products/asn1c/pricing.php

BlaizeLei commented 4 months ago

Okay. Thanks very much.

mouse07410 commented 4 months ago

Closing this issue, as there's little to nothing that I can do, unfortunately.