first
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"crypto/aes"
|
||||
)
|
||||
|
||||
func AesEcbDecrypt(key []byte, src []byte) ([]byte, error) {
|
||||
block, err := aes.NewCipher(key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dst := make([]byte, 0, len(src))
|
||||
tmp := make([]byte, aes.BlockSize)
|
||||
|
||||
for i := 0; i < len(src); i += aes.BlockSize {
|
||||
block.Decrypt(tmp, src[i:i+aes.BlockSize])
|
||||
|
||||
if i == len(src)-aes.BlockSize {
|
||||
pad := int(tmp[len(tmp)-1])
|
||||
if pad > aes.BlockSize {
|
||||
pad = 0
|
||||
}
|
||||
dst = append(dst, tmp[:aes.BlockSize-pad]...)
|
||||
} else {
|
||||
dst = append(dst, tmp...)
|
||||
}
|
||||
}
|
||||
|
||||
return dst, nil
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func ReplaceExtension(filepathStr, newExt string) string {
|
||||
ext := filepath.Ext(filepathStr)
|
||||
return strings.TrimSuffix(filepathStr, ext) + newExt
|
||||
}
|
||||
|
||||
func PathExists(path string) bool {
|
||||
_, err := os.Stat(path)
|
||||
if err == nil {
|
||||
return true
|
||||
}
|
||||
if os.IsNotExist(err) {
|
||||
return false
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func IsDir(path string) bool {
|
||||
s, err := os.Stat(path)
|
||||
if err != nil {
|
||||
|
||||
return false
|
||||
}
|
||||
return s.IsDir()
|
||||
}
|
||||
|
||||
func GetRelativePath(from, to string) string {
|
||||
rel, err := filepath.Rel(from, to)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return rel
|
||||
}
|
||||
|
||||
func IsRegularFile(path string) bool {
|
||||
s, err := os.Stat(path)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return s.Mode().IsRegular()
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/TwiN/go-color"
|
||||
)
|
||||
|
||||
func DonePrintfln(format string, a ...interface{}) {
|
||||
fmt.Printf(color.InBold(color.InGreen("[Done] "))+format+"\n", a...)
|
||||
}
|
||||
|
||||
func InfoPrintfln(format string, a ...interface{}) {
|
||||
fmt.Printf(color.InBold(color.InBlue("[Info] "))+format+"\n", a...)
|
||||
}
|
||||
|
||||
func WarningPrintfln(format string, a ...interface{}) {
|
||||
fmt.Printf(color.InBold(color.InYellow("[Warning] "))+format+"\n", a...)
|
||||
}
|
||||
|
||||
func ErrorPrintfln(format string, a ...interface{}) {
|
||||
fmt.Printf(color.InBold(color.InRed("[Error] "))+format+"\n", a...)
|
||||
}
|
||||
Reference in New Issue
Block a user