-
Notifications
You must be signed in to change notification settings - Fork 51
/
ct.go
57 lines (43 loc) · 1.16 KB
/
ct.go
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
package claimsheader
import (
"strconv"
)
// CompressionType defines the compression used.
type CompressionType int
const (
// CompressionTypeNone implies no compression
CompressionTypeNone CompressionType = iota
// CompressionTypeV1 is version 1 of compression
CompressionTypeV1
// CompressionTypeV2 is version 2 of compression
CompressionTypeV2
)
const (
// CompressedTagLengthV1 is version 1 length of tags
CompressedTagLengthV1 int = 12
// CompressedTagLengthV2 is version 2 length of tags
CompressedTagLengthV2 int = 4
)
func (c CompressionType) toString() string {
return strconv.Itoa(int(c))
}
// CompressionTypeToTagLength converts CompressionType to length.
func CompressionTypeToTagLength(t CompressionType) int {
if t == CompressionTypeNone {
return 0
}
if t == CompressionTypeV1 {
return CompressedTagLengthV1
}
return CompressedTagLengthV2
}
// String2CompressionType is a helper to convert string to compression type
func String2CompressionType(s string) CompressionType {
if s == CompressionTypeV1.toString() {
return CompressionTypeV1
}
if s == CompressionTypeV2.toString() {
return CompressionTypeV2
}
return CompressionTypeNone
}