All Projects → sdaubert → rasn1

sdaubert / rasn1

Licence: MIT license
Ruby ASN.1 library

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to rasn1

der-parser
BER/DER parser written in pure Rust. Fast, zero-copy, safe.
Stars: ✭ 73 (+421.43%)
Mutual labels:  parse, asn1, ber, der
C-plus-plus-ASN.1-2008-coder-decoder
Free C++ ASN.1:2008 coder/decoder
Stars: ✭ 23 (+64.29%)
Mutual labels:  decoder, asn1, ber
rasn
A Safe #[no_std] ASN.1 Codec Framework
Stars: ✭ 131 (+835.71%)
Mutual labels:  asn1, ber, der
asn1-ts
ASN.1 TypeScript library, including codecs for Basic Encoding Rules (BER) and Distinguished Encoding Rules (DER).
Stars: ✭ 26 (+85.71%)
Mutual labels:  asn1, ber, der
pem-utils
Managed .NET (C#) utility library for working with PEM files with DER/ASN.1 encoding
Stars: ✭ 62 (+342.86%)
Mutual labels:  asn1, der
Asn1DerParser.NET
Abstract Syntax Notation One (ASN.1) binary parser to support Distinguished Encoding Rules (DER) in .NET
Stars: ✭ 31 (+121.43%)
Mutual labels:  asn1, der
mpq
Decoder/parser of Blizzard's MPQ archive file format
Stars: ✭ 28 (+100%)
Mutual labels:  parse, decoder
asinine
Embeddable ASN.1 (DER) and X.509v3 decoder
Stars: ✭ 34 (+142.86%)
Mutual labels:  asn1, der
eslump
Fuzz testing JavaScript parsers and suchlike programs.
Stars: ✭ 56 (+300%)
Mutual labels:  parse
keystore-go
A Go (golang) implementation of Java KeyStore encoder/decoder
Stars: ✭ 119 (+750%)
Mutual labels:  decoder
tparse
time parsing library for Go; supports more time units than standard library
Stars: ✭ 42 (+200%)
Mutual labels:  parse
readsb
ADS-B decoder swiss knife
Stars: ✭ 114 (+714.29%)
Mutual labels:  decoder
MarknoteParser
A high performance markdown parser in Swift.
Stars: ✭ 29 (+107.14%)
Mutual labels:  parse
logstash-laravel-logs
Process Laravel Log files on Logstash and forward to ElasticSearch
Stars: ✭ 35 (+150%)
Mutual labels:  parse
png
🖼A full-featured PNG decoder and encoder.
Stars: ✭ 64 (+357.14%)
Mutual labels:  decoder
node-red-contrib-string
Provides a string manipulation node with a chainable UI based on the concise and lightweight stringjs.com.
Stars: ✭ 15 (+7.14%)
Mutual labels:  parse
online-ethereum-abi-encoder-decoder
A quick online tool to abi-encode and abi-decode constructor arguments used in ethereum's solidity. https://adibas03.github.io/online-ethereum-abi-encoder-decoder/
Stars: ✭ 37 (+164.29%)
Mutual labels:  decoder
Mappable
flexible JSON to Model converter, specially optimized for immutable properties
Stars: ✭ 27 (+92.86%)
Mutual labels:  decoder
golgi
A composable routing library for Haxe.
Stars: ✭ 37 (+164.29%)
Mutual labels:  parse
RFFHEM
Counterpart of SIGNALDuino, it's the code for FHEM to work with the data received from the uC
Stars: ✭ 44 (+214.29%)
Mutual labels:  decoder

Gem Version

Rasn1

Rasn1 is a ruby ASN.1 library to encode, parse and decode ASN.1 data in DER format.

Installation

Add this line to your application's Gemfile:

gem 'rasn1'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install rasn1

Simple usage

To decode a DER/BER string without checking a model, do:

decoded_der = RASN1.parse(der_string)
decoded_ber = RASN1.parse(ber_string, ber: true)

Advanced usage

All examples below will be based on:

Record ::= SEQUENCE {
  id        INTEGER,
  room  [0] INTEGER OPTIONAL,
  house [1] INTEGER DEFAULT 0
}

ComplexRecord ::= SEQUENCE {
  bool      BOOLEAN,
  data  [0] EXPLICIT OCTET STRING,
  a_record  Record
}

Create a ASN.1 model

class Record < RASN1::Model
  sequence :record,
           content: [integer(:id),
                     integer(:room, implicit: 0, optional: true),
                     integer(:house, implicit: 1, default: 0)]
end

More comple classes may be designed by nesting simple classes. For example:

class ComplexRecord < RASN1::Model
  sequence :cplx_record,
           content: [boolean(:bool),
                     octet_string(:data, explicit: 0),
                     model(:a_record, Record)]
end

Parse a DER-encoded string

record = Record.parse(der_string)
record[:id]             # => RASN1::Types::Integer
record[:id].value       # => Integer
record[:id].to_i        # => Integer
record[:id].asn1_class  # => Symbol
record[:id].optional?   # => false
record[:id].default     # => nil
record[:room].optional  # => true
record[:house].default  # => 0

record[:id].to_der      # => String

cplx_record = ComplexRecord.parse(der_string)
cplx_record[:bool]            # => RASN1::Types::Boolean
cplx_record[:bool].value      # => TrueClass/FalseClass
cplx_record[:data].value      # => String
cplx_record[:data].explicit?  # => true
cplx_record[:a_record]        # => Record

Generate a DER-encoded string

record = Record.new(id: 12)
record[:id].to_i      # => 12
record[:room]         # => nil
record[:house]        # => 0

# Set one value
record[:room] = 43
record[:room]         # => 43

# Set mulitple values
record.set id: 124, house: 155

record.to_der         # => String

More information

see https://github.com/sdaubert/rasn1/wiki

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/sdaubert/rasn1.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].