Source file cid_intf.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
type version = [ `Cidv0 | `Cidv1 | `Cidv2 | `Cidv3 ]

module type S = sig
  type multihash
  (** The type for multihashes *)

  type t
  (** A content-addressed identifier. *)

  val v :
    version:version ->
    base:Multibase.Encoding.t ->
    codec:Multicodec.t ->
    hash:multihash ->
    t
  (** Build a CID, this performs no checks on any of the inputs *)

  val version : t -> version
  (** The CID version. *)

  val base : t -> Multibase.Encoding.t
  (** The multibase encoding of the CID. *)

  val codec : t -> Multicodec.t
  (** The multicodec type of the data *)

  val hash : t -> multihash
  (** The multihash of the CID *)

  val equal : t -> t -> bool
  (** Tests the equality of two CIDs. *)

  val of_string :
    string ->
    (t, [ `Msg of string | `Unsupported of Multibase.Encoding.t ]) result
  (** [of_string s] takes an encoded string [s] that is the CID and
    pulls out each of the parts that make it up. *)

  val of_cstruct :
    base:Multibase.Encoding.t ->
    Cstruct.t ->
    (t, [ `Msg of string | `Unsupported of Multibase.Encoding.t ]) result
  (** [of_cstruct ~base buf] builds a value representing a CID. The buffer
    should not be encoded with the multibase encoding. *)

  val to_string : t -> string
  (** [to_string t] converts the CID to a multibase encoded string. Errors happen
      if the base encoding is not supported. This may raise an exception of the base
      encoding format is not supported. *)

  val to_cstruct : t -> Cstruct.t
  (** [to_cstruct t] returns a buffer with the bytes corresponding to the unencoded
    CID. *)

  val pp_human : Format.formatter -> t -> unit
  (** Pretty-prints a CID. *)
end

module type Intf = sig
  module type S = S

  module Make (H : Multihash.S) : S with type multihash = Cstruct.t H.t
  include S with type multihash = Cstruct.t Multihash_digestif.t
end