-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
qrgen.clj
68 lines (63 loc) · 2.3 KB
/
qrgen.clj
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
(ns one-time.qrgen
(:require [one-time.uri :as uri])
(:import net.glxn.qrgen.core.image.ImageType
net.glxn.qrgen.javase.QRCode))
(def ^:private image-types
{:JPG ImageType/JPG
:GIF ImageType/GIF
:PNG ImageType/PNG
:BMP ImageType/BMP})
(defn totp-stream
"Returns a java.io.ByteArrayOutputStream with the totp qrcode"
[{:keys [image-type image-size label user secret]
:or {image-type :JPG image-size 125}}]
{:pre [(not-any? nil? [label user secret])
(image-types image-type)]}
(-> (^String uri/totp-uri {:label label
:secret secret
:user user})
(QRCode/from)
(.to (image-types image-type))
(.withSize image-size image-size)
(.stream)))
(defn totp-file
"Returns a java.io.File with the totp qrcode"
[{:keys [image-type image-size label user secret]
:or {image-type :JPG image-size 125}}]
{:pre [(not-any? nil? [label user secret])
(image-types image-type)]}
(-> (^String uri/totp-uri {:label label
:secret secret
:user user})
(QRCode/from)
(.to (image-types image-type))
(.withSize image-size image-size)
(.file)))
(defn hotp-stream
"Returns a java.io.ByteArrayOutputStream with the hotp qrcode"
[{:keys [image-type image-size label user secret counter]
:or {image-type :JPG image-size 125}}]
{:pre [(not-any? nil? [label user secret counter])
(image-types image-type)]}
(-> (^String uri/hotp-uri {:label label
:secret secret
:user user
:counter counter})
(QRCode/from)
(.to (image-types image-type))
(.withSize image-size image-size)
(.stream)))
(defn hotp-file
"Returns a java.io.File with the hotp qrcode"
[{:keys [image-type image-size label user secret counter]
:or {image-type :JPG image-size 125}}]
{:pre [(not-any? nil? [label user secret counter])
(image-types image-type)]}
(-> (^String uri/hotp-uri {:label label
:secret secret
:user user
:counter counter})
(QRCode/from)
(.to (image-types image-type))
(.withSize image-size image-size)
(.file)))