aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com
diff options
context:
space:
mode:
authorEthan Koenig <ethantkoenig@gmail.com>2017-11-28 01:43:51 -0800
committerLunny Xiao <xiaolunwen@gmail.com>2017-11-28 17:43:51 +0800
commitb7ebaf6d2078cbf4de00d0782be8bc1b1de644bb (patch)
tree5ad8ef6f9738883e89559112e965b9a0bf303476 /vendor/github.com
parent6a58e3f9fcb8b9f30345e2f8a5812bda72c6baf5 (diff)
downloadgitea-b7ebaf6d2078cbf4de00d0782be8bc1b1de644bb.tar.gz
gitea-b7ebaf6d2078cbf4de00d0782be8bc1b1de644bb.zip
Various wiki bug fixes (#2996)
* Update macaron * Various wiki bug fixes
Diffstat (limited to 'vendor/github.com')
-rw-r--r--vendor/github.com/Unknwon/com/convert.go10
-rw-r--r--vendor/github.com/Unknwon/com/string.go52
2 files changed, 41 insertions, 21 deletions
diff --git a/vendor/github.com/Unknwon/com/convert.go b/vendor/github.com/Unknwon/com/convert.go
index 25b3e0e562..bf24aa8bc3 100644
--- a/vendor/github.com/Unknwon/com/convert.go
+++ b/vendor/github.com/Unknwon/com/convert.go
@@ -41,6 +41,11 @@ func (f StrTo) Int64() (int64, error) {
return int64(v), err
}
+func (f StrTo) Float64() (float64, error) {
+ v, err := strconv.ParseFloat(f.String(), 64)
+ return float64(v), err
+}
+
func (f StrTo) MustUint8() uint8 {
v, _ := f.Uint8()
return v
@@ -56,6 +61,11 @@ func (f StrTo) MustInt64() int64 {
return v
}
+func (f StrTo) MustFloat64() float64 {
+ v, _ := f.Float64()
+ return v
+}
+
func (f StrTo) String() string {
if f.Exist() {
return string(f)
diff --git a/vendor/github.com/Unknwon/com/string.go b/vendor/github.com/Unknwon/com/string.go
index 4c79820f1f..7080d174a8 100644
--- a/vendor/github.com/Unknwon/com/string.go
+++ b/vendor/github.com/Unknwon/com/string.go
@@ -19,9 +19,7 @@ import (
"crypto/aes"
"crypto/cipher"
"crypto/rand"
- "encoding/base64"
"errors"
- "io"
r "math/rand"
"strconv"
"strings"
@@ -30,41 +28,53 @@ import (
"unicode/utf8"
)
-// AESEncrypt encrypts text and given key with AES.
-func AESEncrypt(key, text []byte) ([]byte, error) {
+// AESGCMEncrypt encrypts plaintext with the given key using AES in GCM mode.
+func AESGCMEncrypt(key, plaintext []byte) ([]byte, error) {
block, err := aes.NewCipher(key)
if err != nil {
return nil, err
}
- b := base64.StdEncoding.EncodeToString(text)
- ciphertext := make([]byte, aes.BlockSize+len(b))
- iv := ciphertext[:aes.BlockSize]
- if _, err := io.ReadFull(rand.Reader, iv); err != nil {
+
+ gcm, err := cipher.NewGCM(block)
+ if err != nil {
return nil, err
}
- cfb := cipher.NewCFBEncrypter(block, iv)
- cfb.XORKeyStream(ciphertext[aes.BlockSize:], []byte(b))
- return ciphertext, nil
+
+ nonce := make([]byte, gcm.NonceSize())
+ if _, err := rand.Read(nonce); err != nil {
+ return nil, err
+ }
+
+ ciphertext := gcm.Seal(nil, nonce, plaintext, nil)
+ return append(nonce, ciphertext...), nil
}
-// AESDecrypt decrypts text and given key with AES.
-func AESDecrypt(key, text []byte) ([]byte, error) {
+// AESGCMDecrypt decrypts ciphertext with the given key using AES in GCM mode.
+func AESGCMDecrypt(key, ciphertext []byte) ([]byte, error) {
block, err := aes.NewCipher(key)
if err != nil {
return nil, err
}
- if len(text) < aes.BlockSize {
- return nil, errors.New("ciphertext too short")
+
+ gcm, err := cipher.NewGCM(block)
+ if err != nil {
+ return nil, err
+ }
+
+ size := gcm.NonceSize()
+ if len(ciphertext)-size <= 0 {
+ return nil, errors.New("Ciphertext is empty")
}
- iv := text[:aes.BlockSize]
- text = text[aes.BlockSize:]
- cfb := cipher.NewCFBDecrypter(block, iv)
- cfb.XORKeyStream(text, text)
- data, err := base64.StdEncoding.DecodeString(string(text))
+
+ nonce := ciphertext[:size]
+ ciphertext = ciphertext[size:]
+
+ plainText, err := gcm.Open(nil, nonce, ciphertext, nil)
if err != nil {
return nil, err
}
- return data, nil
+
+ return plainText, nil
}
// IsLetter returns true if the 'l' is an English letter.