Module Lber
This library implements the subset of ber
type readbyte_error=|End_of_stream|Transport_error|Peek_error|Request_too_large|Not_implemented
exceptionReadbyte_error of readbyte_error
type readbyte= ?peek:bool -> int -> stringtype writebyte= char -> unittype ber_class=|Universal|Application|Context_specific|Privatetype ber_length=|Definite of int|Indefinitetype ber_val_header={ber_class : ber_class;ber_primitive : bool;ber_tag : int;ber_length : ber_length;}
val readbyte_of_string : string -> readbytereturn a readbyte function for a string, currently not implemented
val readbyte_of_ber_element : ber_length -> readbyte -> readbytereturn a readbyte implementation which uses another readbyte, but allows setting a read boundry. Useful for constructing views of the octet stream which end at the end of a ber structure. This is essential for reading certian structures because length is only encoded in the toplevel in order to save space. Currently only implemented for definite lengths.
- raises Readbyte_error
in the event of a an io error, or the end of file
val readbyte_of_fd : Unix.file_descr -> readbytea readbyte implementation which reads from an FD. It implements a peek buffer, so it can garentee that it will work with rb_of_ber_element, even with blocking fds.
- raises Readbyte_error
in the event of a an io error, or the end of file
val readbyte_of_ssl : Ssl.socket -> readbytea readbyte implementation which reads from an SSL socket. It is otherwise the same as readbyte_of_fd.
- raises Readbyte_error
in the event of a an io error, or the end of file
val decode_ber_header : ?peek:bool -> readbyte -> ber_val_headerdecoding and encoding of the ber header
val encode_ber_header : ber_val_header -> stringval read_contents : ?peek:bool -> readbyte -> ber_length -> stringreads the contents octets
val decode_ber_bool : ?peek:bool -> ?cls:ber_class -> ?tag:int -> ?contents:string option -> readbyte -> boolEncoding/Decoding of the boolean primative ASN.1 type. Encode function encodes a valid ber type, including the header and length octets.
val encode_ber_bool : ?cls:ber_class -> ?tag:int -> bool -> stringval decode_ber_int32 : ?peek:bool -> ?cls:ber_class -> ?tag:int -> ?contents:string option -> readbyte -> int32Encoding/Decoding of the integer primative ASN.1 type. Note, in this library, integers are represented as 32 bit values. In ASN.1 there is no practical limit to the size of an integer, later on, this library may provide an encoder/decoder to Int64, and Bigints, however for now, this will have to do. Encode function encodes a valid ber type, including the header and length octets
val encode_ber_int32 : ?cls:ber_class -> ?tag:int -> int32 -> stringval decode_ber_enum : ?peek:bool -> ?cls:ber_class -> ?tag:int -> ?contents:string option -> readbyte -> int32Encoding/Decoding of enum primative ASN.1 type. Enums are simply integers, the same drawbacks apply as for decode_ber_int32. Encode function encodes a valid ber type, including the header and length octets
val encode_ber_enum : ?cls:ber_class -> ?tag:int -> int32 -> stringval decode_ber_octetstring : ?peek:bool -> ?cls:ber_class -> ?tag:int -> ?contents:string option -> readbyte -> stringEncoding/Decoding of octetstring ASN.1 types. The Nested or "segmented" version of the octetstring encoding described in X.690 is not yet supported. Encode function encodes a valid ber type, including the header and length octets
val encode_ber_octetstring : ?cls:ber_class -> ?tag:int -> string -> stringval decode_ber_null : ?peek:bool -> ?cls:ber_class -> ?tag:int -> ?contents:string option -> readbyte -> unitEncoding/Decoding of Null ASN.1 type. Almost useful as an assertion-type operation
val encode_ber_null : ?cls:ber_class -> ?tag:int -> unit -> stringval encode_berval_list : ?buf:Stdlib.Buffer.t -> ('a -> string) -> 'a list -> stringthis function is for encoding lists of bervals, a common case. you pass it a list of things to encode, and an encoding function, and it will apply the encoding function to each element in the list, storing the resulting encoding in a buffer (which you may either pass in or not)
val decode_berval_list : ?lst:'a list -> (readbyte -> 'a) -> readbyte -> 'a listthis is the reverse of the above, it takes a readbyte structure, and returns a list of decoded elements, processed according to the decoder function you pass in. Note, that you MUST pass a readbyte structure built with readbyte_of_string, OR, your reabyte function must raise Stream.Failure when you reach the end of input. Otherwise this function will explode. That said, it is usually not practical to pass anything but a readbyte created by readbyte_of_string so this should not be a huge problem.