package pkcs11

  1. Overview
  2. Docs
Bindings to the PKCS#11 cryptographic API

Install

dune-project
 Dependency

Authors

Maintainers

Sources

pkcs11-0.9.0.tbz
sha256=0a1dc5fb54d3febbb0024b6fe9bb393f25e4ce6aadbc65fcc114345c5ca3982a
md5=c1a9bd7ed535e9fb31f2e6014567c9af

doc/src/pkcs11.cli/pkcs11_cli.ml.html

Source file pkcs11_cli.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
let exclusive_slot_msg =
  "The options --slot-index, --slot-id, --slot-description and \
   --token-label are mutually exclusive."

module Arg = struct

  let slot_index =
    let open Cmdliner.Arg in
    opt (some int) None @@
    info
      ~docv: "INDEX"
      ~doc:("Token slot $(docv). " ^ exclusive_slot_msg)
      [ "s"; "slot"; "slot-index" ]

  let slot_id =
    let open Cmdliner.Arg in
    opt (some int) None @@
    info
      ~docv: "ID"
      ~doc:("Token slot $(docv). " ^ exclusive_slot_msg)
      ["slot-id"]

  let slot_description =
    let open Cmdliner.Arg in
    opt (some string) None @@
    info
      ~docv: "DESCRIPTION"
      ~doc:("Token slot $(docv). $(docv) must not exceed 64 characters. " ^ exclusive_slot_msg)
      ["slot-description"]

  let token_label =
    let open Cmdliner.Arg in
    opt (some string) None @@
    info
      ~docv: "LABEL"
      ~doc:("Token $(docv). $(docv) must not exceed 32 characters. " ^ exclusive_slot_msg)
      ["token-label"]

  let dll =
    let open Cmdliner.Arg in
    opt (some string) None @@
    info
      ~docv: "DLL"
      ~doc: "PKCS#11 DLL to load."
      [ "d"; "dll" ]

  let pin =
    let open Cmdliner.Arg in
    opt (some string) None @@
    info
      ~docv: "PIN"
      ~doc: "$(docv)"
      [ "p"; "pin" ]

  let use_get_function_list =
    let open Cmdliner.Arg in
    let auto =
      info
        ~doc: "Try to use C_GetFunctionList, and if it fails, try again without using it."
        ["indirect_or_direct"]
    in
    let true_ =
      info
        ~doc: "Use C_GetFunctionList."
        ["indirect"]
    in
    let false_ =
      info
        ~doc: "Do not use C_GetFunctionList."
        ["direct"]
    in
    vflag `Auto
      [ `Auto, auto
      ; `True, true_
      ; `False, false_
      ]

  let user_type =
    let open Cmdliner.Arg in
    let converter = enum
        [ "user", P11.User_type.CKU_USER
        ; "so", P11.User_type.CKU_SO
        ]
    in
    opt (some converter) None @@
    info
      ~docv: "USER TYPE"
      ~doc: "Define the $(docv) to use. \
             May be $(i,user) or $(i,so)."
      ["user-type"]
end

module Term = struct
  let slot_index =
    Cmdliner.Arg.value Arg.slot_index

  let slot_id =
    Cmdliner.Arg.value Arg.slot_id

  let slot_description =
    Cmdliner.Arg.value Arg.slot_description

  let token_label =
    Cmdliner.Arg.value Arg.token_label

  let slot index id descr label =
    let open P11.Slot in
    match index, id, descr, label with
      | None, None, None, None -> `Ok (None)
      | Some i, None, None, None -> `Ok (Some (Index i))
      | None, Some i, None, None -> `Ok (Some (Id i))
      | None, None, Some s, None ->
          if String.length s <= 64 then `Ok (Some (Description s))
          else `Error (true, "DESCRIPTION must not exceed 64 characters")
      | None, None, None, Some s ->
          if String.length s <= 32 then  `Ok (Some (Label s))
          else `Error (true, "LABEL must not exceed 32 characters")
      | _ -> `Error (true, exclusive_slot_msg)

  let slot =
    let open Cmdliner.Term in
    ret (const slot
             $ slot_index
             $ slot_id
             $ slot_description
             $ token_label)

  let pin =
    Cmdliner.Arg.value Arg.pin

  let use_get_function_list =
    Cmdliner.Arg.value Arg.use_get_function_list

  let user_type =
    Cmdliner.Arg.value Arg.user_type
end