404 on get returns empty object and right status
parent
5aa121a42e
commit
887e67bc7d
|
|
@ -0,0 +1,43 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
key := os.Args[1]
|
||||
value := os.Args[2]
|
||||
log.Println(aesDec(key, value))
|
||||
}
|
||||
|
||||
func aesDec(key, payload string) (string, error) {
|
||||
if len(key) == 0 {
|
||||
return "", errors.New("key required")
|
||||
}
|
||||
key = strings.Repeat(key, 32)[:32]
|
||||
|
||||
ciphertext, err := base64.StdEncoding.DecodeString(payload)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
block, err := aes.NewCipher([]byte(key))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
gcm, err := cipher.NewGCM(block)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if len(ciphertext) < gcm.NonceSize() {
|
||||
return "", errors.New("short ciphertext")
|
||||
}
|
||||
b, err := gcm.Open(nil, ciphertext[:gcm.NonceSize()], ciphertext[gcm.NonceSize():], nil)
|
||||
return string(b), err
|
||||
}
|
||||
|
|
@ -53,8 +53,8 @@ func whoGet(namespace string, g storage.Graph, w http.ResponseWriter, r *http.Re
|
|||
return err
|
||||
}
|
||||
if len(ones) == 0 {
|
||||
http.NotFound(w, r)
|
||||
return nil
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return json.NewEncoder(w).Encode(entity.One{})
|
||||
}
|
||||
if len(ones) > 1 {
|
||||
return errors.New("more than one result found matching " + id)
|
||||
|
|
|
|||
Loading…
Reference in New Issue