Change Key.Value to Key.Checksum
This commit is contained in:
parent
ea12b6a0d2
commit
b701aa1710
2 changed files with 14 additions and 13 deletions
|
@ -7,10 +7,10 @@ import (
|
|||
)
|
||||
|
||||
type Key struct {
|
||||
Id int64 `json:"id"`
|
||||
IdExercice int64 `json:"idExercice"`
|
||||
Type string `json:"type"`
|
||||
Value [blake2b.KeySize]byte `json:"value"`
|
||||
Id int64 `json:"id"`
|
||||
IdExercice int64 `json:"idExercice"`
|
||||
Type string `json:"type"`
|
||||
Checksum []byte `json:"value"`
|
||||
}
|
||||
|
||||
func (e Exercice) GetKeys() ([]Key, error) {
|
||||
|
@ -24,7 +24,7 @@ func (e Exercice) GetKeys() ([]Key, error) {
|
|||
var k Key
|
||||
k.IdExercice = e.Id
|
||||
|
||||
if err := rows.Scan(&k.Id, &k.IdExercice, &k.Type, &k.Value); err != nil {
|
||||
if err := rows.Scan(&k.Id, &k.IdExercice, &k.Type, &k.Checksum); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
keys = append(keys, k)
|
||||
|
@ -43,21 +43,22 @@ func getHashedKey(raw_value string) [blake2b.KeySize]byte {
|
|||
}
|
||||
|
||||
func (e Exercice) AddRawKey(name string, raw_value string) (Key, error) {
|
||||
return e.AddKey(name, getHashedKey(raw_value))
|
||||
hash := getHashedKey(raw_value)
|
||||
return e.AddKey(name, hash[:])
|
||||
}
|
||||
|
||||
func (e Exercice) AddKey(name string, value [blake2b.KeySize]byte) (Key, error) {
|
||||
if res, err := DBExec("INSERT INTO exercice_keys (id_exercice, type, cksum) VALUES (?, ?, ?)", e.Id, name, value); err != nil {
|
||||
func (e Exercice) AddKey(name string, checksum []byte) (Key, error) {
|
||||
if res, err := DBExec("INSERT INTO exercice_keys (id_exercice, type, cksum) VALUES (?, ?, ?)", e.Id, name, checksum); err != nil {
|
||||
return Key{}, err
|
||||
} else if kid, err := res.LastInsertId(); err != nil {
|
||||
return Key{}, err
|
||||
} else {
|
||||
return Key{kid, e.Id, name, value}, nil
|
||||
return Key{kid, e.Id, name, checksum}, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (k Key) Update() (int64, error) {
|
||||
if res, err := DBExec("UPDATE exercice_keys SET id_exercice = ?, type = ?, cksum = ? WHERE id_key = ?", k.IdExercice, k.Type, k.Value, k.Id); err != nil {
|
||||
if res, err := DBExec("UPDATE exercice_keys SET id_exercice = ?, type = ?, cksum = ? WHERE id_key = ?", k.IdExercice, k.Type, k.Checksum, k.Id); err != nil {
|
||||
return 0, err
|
||||
} else if nb, err := res.RowsAffected(); err != nil {
|
||||
return 0, err
|
||||
|
@ -78,12 +79,12 @@ func (k Key) Delete() (int64, error) {
|
|||
|
||||
func (k Key) Check(val string) bool {
|
||||
hash := getHashedKey(val)
|
||||
if len(k.Value) != len(hash) {
|
||||
if len(k.Checksum) != len(hash) {
|
||||
return false
|
||||
}
|
||||
|
||||
for i := range hash {
|
||||
if k.Value[i] != hash[i] {
|
||||
if k.Checksum[i] != hash[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -130,7 +130,7 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
|
|||
} else {
|
||||
for _, k := range keys {
|
||||
if t == nil {
|
||||
exercice.Keys = append(exercice.Keys, fmt.Sprintf("%x", k.Value)+k.Type)
|
||||
exercice.Keys = append(exercice.Keys, fmt.Sprintf("%x", k.Checksum)+k.Type)
|
||||
} else {
|
||||
exercice.Keys = append(exercice.Keys, k.Type)
|
||||
if PartialValidation {
|
||||
|
|
Reference in a new issue