Skip to content

Commit

Permalink
fix: refactor String utils
Browse files Browse the repository at this point in the history
  • Loading branch information
c18s committed Jan 15, 2024
1 parent 01c95da commit f8f5f80
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions string.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ func (StringUtil) HashCrc32(s string) string {
}

// Parse EMVCoQR string to struct
func (StringUtil) ParseEMVCoQRString(qrString string) (EMVCoQRInfo, error) {
if err := ValidateEMVCoQRString(qrString); err != nil {
func (s StringUtil) ParseEMVCoQRString(qrString string) (EMVCoQRInfo, error) {
if err := s.ValidateEMVCoQRString(qrString); err != nil {
return EMVCoQRInfo{}, err
}
result := EMVCoQRInfo{}
Expand Down Expand Up @@ -195,7 +195,7 @@ func (StringUtil) ParseEMVCoQRString(qrString string) (EMVCoQRInfo, error) {
}

// ValidateEMVCoQRString validates the EMVCoQR string
func ValidateEMVCoQRString(qrString string) error {
func (StringUtil) ValidateEMVCoQRString(qrString string) error {
if len(qrString) < 14 {
return fmt.Errorf("invalid specified qr string length")
}
Expand All @@ -210,7 +210,7 @@ func ValidateEMVCoQRString(qrString string) error {
}

// Encrypt encrypts the given plaintext using AES encryption with the provided key.
func AESEncrypt(key, plaintext string) (string, error) {
func (StringUtil) AESEncrypt(key, plaintext string) (string, error) {
block, err := aes.NewCipher([]byte(key))
if err != nil {
return "", err
Expand All @@ -228,7 +228,7 @@ func AESEncrypt(key, plaintext string) (string, error) {
}

// Decrypt decrypts the given cipherText using AES decryption with the provided key.
func AESDecrypt(key, cipherText string) (string, error) {
func (StringUtil) AESDecrypt(key, cipherText string) (string, error) {
block, err := aes.NewCipher([]byte(key))
if err != nil {
return "", err
Expand Down
4 changes: 2 additions & 2 deletions string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ func TestAESEncryptDecrypt(t *testing.T) {
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
cipherText, err := utils.AESEncrypt(test.key, test.plaintext)
cipherText, err := utils.String.AESEncrypt(test.key, test.plaintext)
assert.NoError(t, err)
decryptedText, err := utils.AESDecrypt(test.key, cipherText)
decryptedText, err := utils.String.AESDecrypt(test.key, cipherText)
assert.NoError(t, err)
assert.Equal(t, test.expected, decryptedText)
})
Expand Down

0 comments on commit f8f5f80

Please sign in to comment.