-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommons.go
41 lines (36 loc) · 1.08 KB
/
commons.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
package criptus
import "log"
var BaseSpecialSign = "2bhw#jfQb%W%PxbcuTPx1fD5ND3dAd4pVZUv$PMBJDJkK"
var BaseSpecialSignLength = len(BaseSpecialSign)
func formatSpecialSign(specialSign, key string, kind any) string {
var length int
var name string
switch kind.(type) {
case AesKeyType:
length = kind.(AesKeyType).Length()
name = kind.(AesKeyType).String()
case DesKeyType:
length = kind.(DesKeyType).Length()
name = kind.(DesKeyType).String()
case TripleKeyType:
length = kind.(TripleKeyType).Length()
name = kind.(TripleKeyType).String()
}
specialSignLength := len(specialSign)
if specialSignLength+len(key) < length {
log.Printf("【WARN】 %s the length of specialSign and key less %d\n", name, length)
if specialSignLength%2 == 0 {
specialSign += BaseSpecialSign[:length-len(specialSign)]
} else {
specialSign += BaseSpecialSign[BaseSpecialSignLength-length:]
}
}
if specialSignLength > length {
if specialSignLength%2 == 0 {
specialSign = specialSign[:length+1]
} else {
specialSign = specialSign[len(specialSign)-length:]
}
}
return specialSign
}