{"id":15136951,"url":"https://github.com/samuel-tyler/fast_ber","last_synced_at":"2025-09-12T03:20:10.972Z","repository":{"id":48079053,"uuid":"156039320","full_name":"Samuel-Tyler/fast_ber","owner":"Samuel-Tyler","description":"A C++11 ASN.1 BER Encoding and Decoding Library","archived":false,"fork":false,"pushed_at":"2021-08-08T11:27:52.000Z","size":1808,"stargazers_count":85,"open_issues_count":16,"forks_count":11,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-30T18:38:10.118Z","etag":null,"topics":["asn","asn-1","asn1","ber","c","cmake","compiler","conan","cpp","decoding","decoding-library","der","encoding"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Samuel-Tyler.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-11-04T01:35:36.000Z","updated_at":"2024-12-26T17:42:50.000Z","dependencies_parsed_at":"2022-08-12T18:10:25.861Z","dependency_job_id":null,"html_url":"https://github.com/Samuel-Tyler/fast_ber","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Samuel-Tyler%2Ffast_ber","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Samuel-Tyler%2Ffast_ber/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Samuel-Tyler%2Ffast_ber/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Samuel-Tyler%2Ffast_ber/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Samuel-Tyler","download_url":"https://codeload.github.com/Samuel-Tyler/fast_ber/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237821687,"owners_count":19371806,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asn","asn-1","asn1","ber","c","cmake","compiler","conan","cpp","decoding","decoding-library","der","encoding"],"created_at":"2024-09-26T06:42:05.438Z","updated_at":"2025-02-08T14:31:20.490Z","avatar_url":"https://github.com/Samuel-Tyler.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fast_ber ![version](https://img.shields.io/github/tag/samuel-tyler/fast_ber.svg) [![Appveyor status](https://ci.appveyor.com/api/projects/status/github/Samuel-Tyler/fast_ber?branch=master\u0026svg=true)](https://ci.appveyor.com/project/Samuel-Tyler/fast-ber) [![Travis status](https://api.travis-ci.com/Samuel-Tyler/fast_ber.svg?branch=master)](https://travis-ci.com/Samuel-Tyler/fast_ber) ![C++11](https://img.shields.io/badge/language-C%2B%2B11-green.svg) ![C++14](https://img.shields.io/badge/language-C%2B%2B14-green.svg) ![C++17](https://img.shields.io/badge/language-C%2B%2B17-green.svg) ![C++20](https://img.shields.io/badge/language-C%2B%2B20-green.svg) ![clang-format](https://github.com/Samuel-Tyler/fast_ber/workflows/clang-format/badge.svg)\nA performant ASN.1 BER encoding and decoding library written in C++11\n\n## Introduction\nfast_ber is a small, lightweight library for BER encoding and decoding. Fast ber forgoes some tight ASN.1 specification conformance to provide fast encoding and decoding performance in common use cases\n\n#### Design Decisions\n- Simple, modern C++ interface\n- ASN.1 sequences are represented as POD structs - no private members or complex getters and setters\n- No exceptions, no RTTI and limited memory allocations (everything is small buffer optimised)\n- View classes are provided for zero copy decoding\n- Interfaces mimic STL types such as std::string, std::vector and std::optional\n\n[Read more about the decisions made writing this library](https://medium.com/@samtyler6/translating-asn-1-ber-types-to-modern-c-226fb06d026f)\n\n#### Limitations\n- No circular data structures\n- Size and value constraints are not implemented\n\n### Tools\nfast_ber_view can be used to dump the contents of a BER PDU, without requiring a schema.\n```\n./build/src/fast_ber_view ./build_gcc/sample/pokemon.ber | jq\n{\n  \"length\": 125,\n  \"identifier\": {\n    \"class\": \"Universal\",\n    \"tag\": \"Sequence / Sequence Of\"\n  },\n  \"content\": ...\n}\n```\n\n## Call for Test Data\nTest data is wanted to improve this project! If you have any test ASN.1 specs or BER files please share them. More test data will improve parsing and help find any issues with the library.\n\n## Example Project\n`fast_ber` is designed to be easy to consume via CMake. This is demonstrated in [`fast_ber_ldap3`](https://github.com/Samuel-Tyler/fast_ber_ldap3), an example project using `fast_ber` to create and dissect LDAP3 certificates.\n\n## Compiler Usage\n1. Build the compiler:\n```\ngit submodule update --init\nmkdir build_cmake\ncd build_cmake\ncmake ..\nmake\nctest\n```\n\n2. Define an ASN.1 file - Example: pokemon.asn\n```\nPokemon DEFINITIONS EXPLICIT TAGS ::= BEGIN\n\nTeam ::= SEQUENCE {\n    team-name OCTET STRING,\n    members SEQUENCE OF Pokemon\n}\n\nPokemon ::= SEQUENCE {\n    name OCTET STRING,\n    category OCTET STRING,\n    type Type,\n    ability OCTET STRING,\n    weakness OCTET STRING,\n    weight INTEGER\n}\n\nType ::= ENUMERATED {\n    normal,\n    fire,\n    fighting,\n    water,\n    flying,\n    grass\n}\n\nEND\n```\n\n3. Compile an asn file into a header file defining the ber structure\n```\ncd build_cmake\n./src/fast_ber_compiler pokemon.asn pokemon\n```\noutput:\n```\n#pragma once\n\n#include \"fast_ber/ber_types/All.hpp\"\n#include \"pokemon.fwd.hpp\"\n\n\nnamespace fast_ber {\nusing namespace abbreviations;\n\nnamespace Pokemon {\n\nenum class TypeValues {\n    normal,\n    fire,\n    fighting,\n    water,\n    flying,\n    grass,\n};\n\ntemplate \u003ctypename Identifier\u003e\nFAST_BER_ALIAS(Type, Enumerated\u003cTypeValues\u003e);\n\ntemplate \u003ctypename Identifier\u003e\nstruct Pokemon {\n    OctetString\u003c\u003e name;\n    OctetString\u003c\u003e category;\n    Type\u003c\u003e type;\n    OctetString\u003c\u003e ability;\n    OctetString\u003c\u003e weakness;\n    Integer\u003c\u003e weight;\n};\n\ntemplate \u003ctypename Identifier\u003e\nstruct Team {\n    OctetString\u003c\u003e team_name;\n    SequenceOf\u003cPokemon\u003c\u003e\u003e members;\n};\n\n} // End namespace Pokemon\n} // End namespace fast_ber\n```\n\n4. Include the header file into your application. Fields in the generated structure can be assigned to standard types. Encode and decode functions are used to serialize and deserialize the data\n```\n#include \"pokemon.hpp\"\n\nint main()\n{\n    fast_ber::Pokemon::Team\u003c\u003e    team    = {\"Sam's Team\"};\n    fast_ber::Pokemon::Pokemon\u003c\u003e muchlax = { \"Munchlax\",\n                                             \"Big Eater\",\n                                             fast_ber::Pokemon::Type\u003c\u003e::Values::normal,\n                                             \"Thick Fat, Pickup\",\n                                             \"Fighting\",\n                                             105 };\n    fast_ber::Pokemon::Pokemon\u003c\u003e piplup  = { \"Piplup\",\n                                             \"Penguin\",\n                                             fast_ber::Pokemon::Type\u003c\u003e::Values::water,\n                                             Torrent\",\n                                             \"Electric, Grass\",\n                                             12 };\n    team.members.push_back(muchlax);\n    team.members.push_back(piplup);\n\n    std::array\u003cuint8_t, 2000\u003e buffer{};\n    const auto                encode_result = fast_ber::encode(absl::Span\u003cuint8_t\u003e(buffer), team);\n    if (!encode_result.success)\n    {\n        return -1;\n    }\n\n    return 0;\n}\n```\n\nTake a look at [`fast_ber_ldap3`](https://github.com/Samuel-Tyler/fast_ber_ldap3) for an example of these steps in action.\n\n## Features\nfast_ber is in development. The following table documents what has been implemented and what features are coming soon\n\n| Type | Implemented |\n| --- | --- |\n| Integer | Yes |\n| Boolean | Yes |\n| Strings | Yes |\n| Sequence | Yes |\n| Sequence Of | Yes |\n| Choice | Yes |\n| Set | No |\n| Set Of | Yes |\n| Enumerated | Yes |\n| Object Identifier | Yes |\n| Dates / Times | No |\n| Null | Yes |\n| Any | No |\n\n| Feature | Implemented |\n| --- | --- |\n| Explicit tags | Yes |\n| Implicit tags | Yes |\n| Indefinitive length | No |\n| Arbitrary top level structure | Yes |\n| Arbritary definition order | Yes |\n| Embedded Types | Yes |\n| Imports | Yes |\n\n## Possible Future Extensions\nThe following features may be added in the future\n\n```\nPartial decoding\nPartial encode at compile time (templated / constexpr)\nHigh / low conformance modes\nDER mode\n```\n\n## Benchmarks\n\nfast_ber includes benchmarks against asn1c, an ASN library written in C. Here is an example of the output:\n```\n-------------------------------------------------------------------------------\nBenchmark: Decode Performance\n-------------------------------------------------------------------------------\n...............................................................................\n\nbenchmark name                                  iters   elapsed ns      average\n-------------------------------------------------------------------------------\nfast_ber        - 1,000,000 x decode 2107B pdu      1    516381442   516.381 ms\nasn1c           - 1,000,000 x decode 2107B pdu      1   4996255249    4.99626 s\nfast_ber        - 1,000,000 x decode 64B pdu        1    192230063    192.23 ms\nasn1c           - 1,000,000 x decode 64B pdu        1   2581069031    2.58107 s\n\n-------------------------------------------------------------------------------\nBenchmark: Encode Performance\n-------------------------------------------------------------------------------\n...............................................................................\n\nbenchmark name                                  iters   elapsed ns      average\n-------------------------------------------------------------------------------\nfast_ber        - 1,000,000 x encode 2107B pdu      1    191266512   191.267 ms\nasn1c           - 1,000,000 x encode 2107B pdu      1   7349946740    7.34995 s\n\n-------------------------------------------------------------------------------\nBenchmark: Object Construction Performance\n-------------------------------------------------------------------------------\n...............................................................................\n\nbenchmark name                                  iters   elapsed ns      average\n-------------------------------------------------------------------------------\nfast_ber        - 1,000,000 x construct data        1   1005938231    1.00594 s\nasn1c           - 1,000,000 x construct data        1    511881940   511.882 ms\n\n-------------------------------------------------------------------------------\nBenchmark: Calculate Encoded Length Performance\n-------------------------------------------------------------------------------\n...............................................................................\n\nbenchmark name                                  iters   elapsed ns      average\n-------------------------------------------------------------------------------\nfast_ber        - 1,000,000 x encoded length        1     17084558   17.0846 ms\n\n===============================================================================\nAll tests passed (31 assertions in 8 test cases)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamuel-tyler%2Ffast_ber","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamuel-tyler%2Ffast_ber","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamuel-tyler%2Ffast_ber/lists"}