Module Crypto.Bytes

The module for bytes.

type t = bytes

The type for byte buffers.

val create : int -> init:int -> t

create n ~init is a byte buffer of length n filled with byte init.

val init : int -> init:( int -> int ) -> t

init n ~init is a byte bufer of length n with init i called to initialize index i.

val length : t -> int

length b is the length of b.

val get : t -> int -> int

get b i is the byte at index i of b.

val set : t -> int -> int -> unit

set b i v sets the byte at index i of b to v.

val copy : t -> t

copy b is a copy of b.

val clear : t -> unit

clear b fills b with 0.

val blit : src:t -> int -> dst:t -> int -> len:int -> unit

blit ~src i ~dst k ~len copies the len bytes of src starting at i to those of dst starting at k.

Converting

val of_string : string -> t

of_string s are the bytes of s.

val to_string : t -> string

to_string b are the bytes of b as a string.

val of_bytes : bytes -> t

of_bytes b are the bytes of b.

val to_bytes : t -> bytes

to_bytes b are the bytes of b as bytes.

val of_bigbytes : bigbytes -> t

of_bigbytes b are the bytes of b.

val to_bigbytes : t -> bigbytes

to_bigbytes b are the bytes of b as bigbytes.

Textual

type hex_error =
| Odd_hex_digits
| Illegal_char of Stdlib.Char.t * int(*

Character and byte index.

*)

The type for textual hexadecimal conversion errors.

val hex_error_message : hex_error -> string

hex_error_message e is an english error message for e.

val of_hex : string -> ( t, hex_error ) Stdlib.result

of_hex s parses bytes from s. Drops space (U+0020) or minus (U+002D) characters and then parses any even sequence of US-ASCII upper or lowercase hexadecimal digits (U+0030–0+0039, U+0041–U+0046, U+0061-U+0066) into a byte sequence.

val of_hex' : string -> ( t, string ) Stdlib.result

of_hex' s is Result.map_error hex_error_message (of_hex s).

val to_hex : ?sep:char -> t -> string

to_hex ?sep b formats b as lowercase hexadecimal digits with bytes separated by sep (if provided; use either ' ' or '-' if you want to round trip with of_hex).

Formatting

val pp : Stdlib.Format.formatter -> t -> unit

pp formats bytes in lowercased hex with a space between each byte.