build(init):项目加入版本库控制。

This commit is contained in:
徐涛
2023-07-17 22:17:40 +08:00
commit 86834970b5
34 changed files with 2149 additions and 0 deletions

52
types/crc16.go Normal file
View File

@@ -0,0 +1,52 @@
package types
import (
"fmt"
"archgrid.xyz/ag/toolsbox/hash/crc16"
)
type CRC16Algorithm string
const (
CRC16_CCITT CRC16Algorithm = "ccitt"
CRC16_CCITT_FALSE CRC16Algorithm = "ccitt-false"
CRC16_SCSI CRC16Algorithm = "scsi"
CRC16_IBM CRC16Algorithm = "ibm"
CRC16_MBUS CRC16Algorithm = "mbus"
)
func (a *CRC16Algorithm) String() string {
return string(*a)
}
func (a *CRC16Algorithm) Set(s string) error {
switch s {
case "ccitt", "ccitt-false", "scsi", "ibm", "mbus":
*a = CRC16Algorithm(s)
return nil
default:
return fmt.Errorf("不支持的CRC16算法%s", s)
}
}
func (a *CRC16Algorithm) Type() string {
return "CRC16Algorithm"
}
func (a CRC16Algorithm) IntoCRC16Mode() crc16.CRC16Mode {
switch a {
case CRC16_CCITT:
return crc16.CCITT
case CRC16_CCITT_FALSE:
return crc16.CCITT_FALSE
case CRC16_SCSI:
return crc16.SCSI
case CRC16_IBM:
return crc16.IBM
case CRC16_MBUS:
return crc16.MBUS
default:
return crc16.IBM
}
}

46
types/crc32.go Normal file
View File

@@ -0,0 +1,46 @@
package types
import (
"fmt"
"archgrid.xyz/ag/toolsbox/hash/crc32"
)
type CRC32Algorithm string
const (
CRC32_IEEE CRC32Algorithm = "ieee"
CRC32_CASTAGNOLI CRC32Algorithm = "castagnoli"
CRC32_KOOPMAN CRC32Algorithm = "koopman"
)
func (a *CRC32Algorithm) String() string {
return string(*a)
}
func (a *CRC32Algorithm) Set(s string) error {
switch s {
case "ieee", "castagnoli", "koopman":
*a = CRC32Algorithm(s)
return nil
default:
return fmt.Errorf("不支持的CRC32算法%s", s)
}
}
func (a *CRC32Algorithm) Type() string {
return "CRC32Algorithm"
}
func (a CRC32Algorithm) IntoCRC32Mode() crc32.CRC32Mode {
switch a {
case CRC32_IEEE:
return crc32.IEEE
case CRC32_CASTAGNOLI:
return crc32.Castagnoli
case CRC32_KOOPMAN:
return crc32.Koopman
default:
return crc32.IEEE
}
}

43
types/crc64.go Normal file
View File

@@ -0,0 +1,43 @@
package types
import (
"fmt"
"archgrid.xyz/ag/toolsbox/hash/crc64"
)
type CRC64Algorithm string
const (
CRC64_ISO CRC64Algorithm = "iso"
CRC64_ECMA CRC64Algorithm = "ecma"
)
func (a *CRC64Algorithm) String() string {
return string(*a)
}
func (a *CRC64Algorithm) Set(s string) error {
switch s {
case "iso", "ecma":
*a = CRC64Algorithm(s)
return nil
default:
return fmt.Errorf("不支持的CRC64算法%s", s)
}
}
func (a *CRC64Algorithm) Type() string {
return "CRC64Algorithm"
}
func (a CRC64Algorithm) IntoCRC64Mode() crc64.CRC64Mode {
switch a {
case CRC64_ISO:
return crc64.ISO
case CRC64_ECMA:
return crc64.ECMA
default:
return crc64.ISO
}
}

67
types/crc8.go Normal file
View File

@@ -0,0 +1,67 @@
package types
import (
"fmt"
"archgrid.xyz/ag/toolsbox/hash/crc8"
)
type CRC8Algorithm string
const (
CRC8_Origin CRC8Algorithm = "crc8"
CRC8_CDMA2000 CRC8Algorithm = "cdma2000"
CRC8_DARC CRC8Algorithm = "darc"
CRC8_DVB_S2 CRC8Algorithm = "dvb-s2"
CRC8_EBU CRC8Algorithm = "ebu"
CRC8_I_CODE CRC8Algorithm = "i-code"
CRC8_ITU CRC8Algorithm = "itu"
CRC8_MAXIM CRC8Algorithm = "maxim"
CRC8_ROHC CRC8Algorithm = "rohc"
CRC8_WCDMA CRC8Algorithm = "wcdma"
)
func (a *CRC8Algorithm) String() string {
return string(*a)
}
func (a *CRC8Algorithm) Set(s string) error {
switch s {
case "crc8", "cdma2000", "darc", "dvb-s2", "ebu", "i-code", "itu", "maxim", "rohc", "wcdma":
*a = CRC8Algorithm(s)
return nil
default:
return fmt.Errorf("不支持的CRC8算法%s", s)
}
}
func (a *CRC8Algorithm) Type() string {
return "CRC8Algorithm"
}
func (a CRC8Algorithm) IntoCRC8Mode() crc8.CRC8Mode {
switch a {
case CRC8_Origin:
return crc8.ORIGIN
case CRC8_CDMA2000:
return crc8.CDMA2000
case CRC8_DARC:
return crc8.DARC
case CRC8_DVB_S2:
return crc8.DVB_S2
case CRC8_EBU:
return crc8.EBU
case CRC8_I_CODE:
return crc8.I_CODE
case CRC8_ITU:
return crc8.ITU
case CRC8_MAXIM:
return crc8.MAXIM
case CRC8_ROHC:
return crc8.ROHC
case CRC8_WCDMA:
return crc8.WCDMA
default:
return crc8.ORIGIN
}
}

28
types/encoding.go Normal file
View File

@@ -0,0 +1,28 @@
package types
import "fmt"
type ResultEncoding string
const (
ResultInBase64 ResultEncoding = "base64"
ResultInHex ResultEncoding = "hex"
)
func (re *ResultEncoding) String() string {
return string(*re)
}
func (re *ResultEncoding) Set(s string) error {
switch s {
case "base64", "hex":
*re = ResultEncoding(s)
return nil
default:
return fmt.Errorf("不支持的编码方式:%s", s)
}
}
func (re *ResultEncoding) Type() string {
return "ResultEncoding"
}

View File

@@ -0,0 +1,32 @@
package types
import (
"fmt"
"strings"
)
type EncryptionPadding string
const (
PKCS7Padding EncryptionPadding = "pkcs7"
ZeroPadding EncryptionPadding = "zero"
NoPadding EncryptionPadding = "no"
)
func (ep *EncryptionPadding) String() string {
return string(*ep)
}
func (ep *EncryptionPadding) Set(s string) error {
switch strings.ToLower(s) {
case "pkcs7", "zero", "no":
*ep = EncryptionPadding(s)
return nil
default:
return fmt.Errorf("不支持的填充方式:%s", s)
}
}
func (ep *EncryptionPadding) Type() string {
return "EncryptionPadding"
}

43
types/rsa.go Normal file
View File

@@ -0,0 +1,43 @@
package types
import (
"fmt"
"archgrid.xyz/ag/toolsbox/encryption/rsa"
)
type RSAKeyBits string
const (
RSA1024 RSAKeyBits = "1024"
RSA2048 RSAKeyBits = "2048"
)
func (r *RSAKeyBits) String() string {
return string(*r)
}
func (r *RSAKeyBits) Set(s string) error {
switch s {
case "1024", "2048":
*r = RSAKeyBits(s)
return nil
default:
return fmt.Errorf("不支持的RSA密钥长度%s", s)
}
}
func (r *RSAKeyBits) Type() string {
return "RSAKeyBits"
}
func (r RSAKeyBits) IntoRSAKeyLength() rsa.KeyLength {
switch r {
case RSA1024:
return rsa.RSA1024
case RSA2048:
return rsa.RSA2048
default:
return rsa.RSA2048
}
}