Giter Club home page Giter Club logo

asn1cpp's Introduction

asn1cpp: A memory-safe C++ wrapper on top of asn1c

This project tries to create a memory-safe and easy to use modern C++ wrapper around the code generated by the asn1c project.

The project is completely header-only: just include the headers in your project and you're ready to use it.

Feel free to explore the test folder in order to see examples on how the library is used.

Requirements

This library only requires that you have a C++11 compliant compiler, and nothing else.

Building the tests

The repository includes a series of tests. The tests are not necessary if you just wish to use the library.

If you wish to build and run them, you need first to install the Boost Test library.

Then you can simply follow the following instructions from the repository's root folder:

git submodule init
git submodule update
mkdir build
cd build
cmake ..
make

This will build all the tests. To run the tests, run:

ctest -V

from the build folder you have created.

To run the tests with valgrind, run:

ctest -D ExperimentalMemCheck -V

Documentation

The asn1cpp library is fully documented.

The Doxygen documentation will export only the API of the library, so to avoid providing you with unnecessary text to read. To generate the Doxygen documentation simply run

doxygen

Within the project's folder. It will automatically create an html folder which contains the generated documentation. Detailed informations on the library's usage can be found under the Related Pages section.

In order to have more information about the internals feel free to read the documentation in the code itself. This should be unnecessary in order to simply use the library, and should be needed only if you need to extend some particular functionality.

asn1cpp's People

Contributors

svalorzen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

asn1cpp's Issues

template parameter redefines default argument error when compiling with Clang.

Hi,

When I tried compiling the test project with Clang 10, both on Windows and in WSL Ubuntu 20.04, I got the error template parameter redefines default argument:

D:\Projects\TestASN1\TestASN1\external\asn1cpp\Encoding.hpp(29,42): error : template parameter redefines default argument
          template <typename T, typename = typename std::enable_if<is_asn1_wrapper<T>::value>::type>
                                           ^
D:\Projects\TestASN1\TestASN1\external\asn1cpp\Seq.hpp(18,42): note: previous default template argument defined here
          template <typename T, typename = typename std::enable_if<is_asn1_wrapper<T>::value>::type>
                                           ^

However, the same code compiled just fine with MSVC 19.26 on Windows and GCC 9.3 on Ubuntu. Is this the intended behavior? I just want to ask so that I can make a note in my readme later.

Thank you so much for your time and help.

Help to compile on Windows

Help me to make it work using Visual Studio. When I import the headers I receive some compilation errors.

My code:

auto sigPolHash = asn1cpp::makeSeq(SigPolicyHash);
asn1cpp::setField(sigPolHash->hashAlgorithm, "1.2.840.113549.1.9.16.2.15");
asn1cpp::setField(sigPolHash->hashValue, "\x89\xA5\xEA\x68\xCC\x0F\x7E\x4E\x89\xA6\x23\xBF\xA6\xC8\x40\x75\xCB\xAF\x44\x35\x35\x5B\x82\x84\x56\xFF\xD1\x44\x8E\x5B\xA3\x52");
auto value = asn1cpp::getField(sigPolHash->hashAlgorithm, std::string);

Compilation error:

1>c:\project\include\asn1cpp\view.hpp(285): error C2976: 'asn1cpp::Impl::Setter': too few template arguments
1>c:\project\include\asn1cpp\view.hpp(14): note: see declaration of 'asn1cpp::Impl::Setter'
1>c:\project\include\asn1cpp\view.hpp(289): note: see reference to class template instantiation 'asn1cpp::View<T>' being compiled
1>c:\project\include\asn1cpp\setter.hpp(35): error C2976: 'asn1cpp::Impl::Setter': too few template arguments
1>c:\project\include\asn1cpp\setter.hpp(29): note: see declaration of 'asn1cpp::Impl::Setter'
1>c:\project\include\asn1cpp\setter.hpp(43): error C2913: explicit specialization; 'asn1cpp::Impl::Setter' is not a specialization of a class template
1>c:\project\include\asn1cpp\setter.hpp(59): error C2913: explicit specialization; 'asn1cpp::Impl::Setter' is not a specialization of a class template
1>c:\project\include\asn1cpp\setter.hpp(72): error C2913: explicit specialization; 'asn1cpp::Impl::Setter' is not a specialization of a class template

I am using Microsoft Windows 2017 with toolset v141.

How to use pushList with a sequence of choice?

Hi,

I'm making use of asn1cpp for a project and so far everything has been working perfectly. Recently, I have encountered an issue when trying to create a sequence of CHOICE that looks like this:

ISO14823Attributes::= SEQUENCE (SIZE(1..8,...)) OF CHOICE{
	dtm DTM, 	-- Date/Time/Period	
	edt	EDT,	-- Exemption status of Date/Time/Period	
	dfl	DFL,	-- Directional Flow of Lane	
	ved	VED, 	-- Vehicle Dimensions
	spe	SPE, 	-- Speed
	roi	ROI,	-- Rate of Incline
	dbv	DBV,	-- Distance Between Vehicles
	ddd	DDD 	-- Destination/Direction/Distance
	}

With this sequence the asn1c generated ISO14823Attributes.h defines the sequence as: A_SEQUENCE_OF(ISO14823Attributes__Member) list; and with the ISO14823Attributes__Member struct defined in the same .h file(I'm attaching the file for better understanding).
The issue is that when trying to create a sequence of the member struct with asn1cpp::makeSeq(ISO14823Attributes__Member) I get an error because it doesn't have an asn type descriptor. On the other hand, a problem arises when trying to manually set the fields
inside the member struct and then trying to do sequenceof::pushList() like this:

auto attr = asn1cpp::makeSeq(ISO14823Attributes);

ISO14823Attributes__Member attr_m;
attr_m.present = ISO14823Attributes__Member_PR_spe;
attr_m.choice.spe = spe_content;

asn1ccp::sequenceOf::pushList(*attr,attr_m);

The error that I get when trying to build says that there is no match for the call to (asn1cpp::Impl::Setter<ISO14823Attributes__Member, void>) (ISO14823Attributes__Member*&, const ISO14823Attributes__Member&).

In an attempt to solve the issue, I added a new macro based on pushList that avoids the use of asn1cpp::setterField() like it is done in asn1cpp::setOf::adderElement() that look like this:

 template <typename T, typename V>
        bool adderChoice(T & field, const V & value) {
            V *ptr = static_cast<V*>(calloc(1,sizeof(V)));

            if(!ptr) {
                return false;
            }

            *ptr=value;

            return ASN_SET_ADD(&field, ptr) == 0;
        } 

With this, I was able to successfully create the sequence but another error comes up when the destructor of the Seq<ISO14823Attributes> object is destroyed and the line def_->op->free_struct(def_, seq_, ASFM_FREE_EVERYTHING); in Seq.hpp, is called. As far as I understand this issue has to do with the fact that avoiding the use of asn1cpp::setterField() also means avoiding the use of the View object that takes care of some memory handling but I don't fully understand how it works.

I would like to ask if there is something I'm missing or if there is any other way to treat this kind of structure "SEQUENCE OF CHOICE". I also let you the .asn containing this structure in case it serves of any help.

Thank you very much in advance for your time and help.
files.zip

How can I use pushList with an optional sequence of sequence?

Hi,

I'm trying out the asn1cpp for my project and everything seems to be working fine. However, I'm having problem with creating an optional sequence. The schema is something like this:

Message ::= SEQUENCE
{
       header MessageHeader,
       content MessageContent,
       content-seqOf SEQUENCE SIZE (1..4) OF MessageContent OPTIONAL
}

I can create the header and the main content sequence using asn1cpp::makeSeq just fine. However, when I tried to create another MessageContent to push it into the content-seqOf, the pushList macro always return false.

auto encode_message = asn1cpp::makeSeq(Message);
auto sub_content= asn1cpp::makeSeq(MessageContent);
auto result = asn1cpp::sequenceof::pushList(*encode_message->content-seqOf, sub_content);

I tried both setOf and sequenceOf but none succeeded.

Thank you so much for your time and help.

How to get/set BIT_STRING_t

BIT_STRING_t define like this:
DriveBehavior ::= BIT STRING {
goStraightForward(0),
laneChangingToLeft(1),
laneChangingToRight(2)
} (SIZE(14,...))

What can I get/set bitstring by getField or setField?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.