Stores ignorecase property for flags
This commit is contained in:
parent
3146e75ead
commit
f36e1c4e4d
6 changed files with 19 additions and 13 deletions
|
@ -191,6 +191,7 @@ func deleteExerciceHint(hint fic.EHint, _ []byte) (interface{}, error) {
|
||||||
type uploadedKey struct {
|
type uploadedKey struct {
|
||||||
Label string
|
Label string
|
||||||
Help string
|
Help string
|
||||||
|
ICase bool
|
||||||
Key string
|
Key string
|
||||||
Hash []byte
|
Hash []byte
|
||||||
}
|
}
|
||||||
|
@ -205,7 +206,7 @@ func createExerciceKey(exercice fic.Exercice, body []byte) (interface{}, error)
|
||||||
return nil, errors.New("Key not filled")
|
return nil, errors.New("Key not filled")
|
||||||
}
|
}
|
||||||
|
|
||||||
return exercice.AddRawKey(uk.Label, uk.Help, uk.Key)
|
return exercice.AddRawKey(uk.Label, uk.Help, uk.ICase, uk.Key)
|
||||||
}
|
}
|
||||||
|
|
||||||
func showExerciceKey(key fic.Key, _ fic.Exercice, body []byte) (interface{}, error) {
|
func showExerciceKey(key fic.Key, _ fic.Exercice, body []byte) (interface{}, error) {
|
||||||
|
@ -225,6 +226,7 @@ func updateExerciceKey(key fic.Key, exercice fic.Exercice, body []byte) (interfa
|
||||||
}
|
}
|
||||||
|
|
||||||
key.Help = uk.Help
|
key.Help = uk.Help
|
||||||
|
key.IgnoreCase = uk.ICase
|
||||||
key.Checksum = uk.Hash
|
key.Checksum = uk.Hash
|
||||||
|
|
||||||
if _, err := key.Update(); err != nil {
|
if _, err := key.Update(); err != nil {
|
||||||
|
|
|
@ -56,6 +56,7 @@ type ExerciceFlagUCQChoice struct {
|
||||||
type ExerciceFlagUCQ struct {
|
type ExerciceFlagUCQ struct {
|
||||||
Label string `toml:",omitempty"`
|
Label string `toml:",omitempty"`
|
||||||
Raw string
|
Raw string
|
||||||
|
IgnoreCase bool `toml:",omitempty"`
|
||||||
Help string `toml:",omitempty"`
|
Help string `toml:",omitempty"`
|
||||||
DisplayAs string `toml:",omitempty"`
|
DisplayAs string `toml:",omitempty"`
|
||||||
Choices_Cost int64 `toml:",omitempty"`
|
Choices_Cost int64 `toml:",omitempty"`
|
||||||
|
|
|
@ -40,7 +40,7 @@ func SyncExerciceKeys(i Importer, exercice fic.Exercice) (errs []string) {
|
||||||
errs = append(errs, fmt.Sprintf("%q: WARNING flag #%d: non-printable characters in flag, is this really expected?", path.Base(exercice.Path), nline + 1))
|
errs = append(errs, fmt.Sprintf("%q: WARNING flag #%d: non-printable characters in flag, is this really expected?", path.Base(exercice.Path), nline + 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
if k, err := exercice.AddRawKey(flag.Label, flag.Help, flag.Raw); err != nil {
|
if k, err := exercice.AddRawKey(flag.Label, flag.Help, flag.IgnoreCase, flag.Raw); err != nil {
|
||||||
errs = append(errs, fmt.Sprintf("%q: error flag #%d: %s", path.Base(exercice.Path), nline + 1, err))
|
errs = append(errs, fmt.Sprintf("%q: error flag #%d: %s", path.Base(exercice.Path), nline + 1, err))
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
|
@ -67,7 +67,7 @@ func SyncExerciceKeys(i Importer, exercice fic.Exercice) (errs []string) {
|
||||||
errs = append(errs, fmt.Sprintf("%q: WARNING flag UCQ #%d: non-printable characters in flag, is this really expected?", path.Base(exercice.Path), nline + 1))
|
errs = append(errs, fmt.Sprintf("%q: WARNING flag UCQ #%d: non-printable characters in flag, is this really expected?", path.Base(exercice.Path), nline + 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
if k, err := exercice.AddRawKey(flag.Label, flag.Help, flag.Raw); err != nil {
|
if k, err := exercice.AddRawKey(flag.Label, flag.Help, flag.IgnoreCase, flag.Raw); err != nil {
|
||||||
errs = append(errs, fmt.Sprintf("%q: error flag UCQ #%d: %s", path.Base(exercice.Path), nline + 1, err))
|
errs = append(errs, fmt.Sprintf("%q: error flag UCQ #%d: %s", path.Base(exercice.Path), nline + 1, err))
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -161,6 +161,7 @@ CREATE TABLE IF NOT EXISTS exercice_keys(
|
||||||
id_exercice INTEGER NOT NULL,
|
id_exercice INTEGER NOT NULL,
|
||||||
type VARCHAR(255) NOT NULL,
|
type VARCHAR(255) NOT NULL,
|
||||||
help VARCHAR(255) NOT NULL,
|
help VARCHAR(255) NOT NULL,
|
||||||
|
ignorecase BOOLEAN NOT NULL DEFAULT 0,
|
||||||
cksum BINARY(64) NOT NULL,
|
cksum BINARY(64) NOT NULL,
|
||||||
FOREIGN KEY(id_exercice) REFERENCES exercices(id_exercice)
|
FOREIGN KEY(id_exercice) REFERENCES exercices(id_exercice)
|
||||||
) DEFAULT CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
|
) DEFAULT CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
|
||||||
|
|
|
@ -290,7 +290,7 @@ func (f EFile) GetDepends() ([]Key, error) {
|
||||||
if err := rows.Scan(&d); err != nil {
|
if err := rows.Scan(&d); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
deps = append(deps, Key{d, f.IdExercice, "", "", []byte{}})
|
deps = append(deps, Key{d, f.IdExercice, "", "", false, []byte{}})
|
||||||
}
|
}
|
||||||
if err := rows.Err(); err != nil {
|
if err := rows.Err(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -16,13 +16,15 @@ type Key struct {
|
||||||
Label string `json:"label"`
|
Label string `json:"label"`
|
||||||
// Help is a small piece of text that aims to add useful information like flag format, ...
|
// Help is a small piece of text that aims to add useful information like flag format, ...
|
||||||
Help string `json:"help"`
|
Help string `json:"help"`
|
||||||
|
// IgnoreCase indicates if the case is sensitive to case or not
|
||||||
|
IgnoreCase bool `json:"ignorecase"`
|
||||||
// Checksum is the expected hashed flag
|
// Checksum is the expected hashed flag
|
||||||
Checksum []byte `json:"value"`
|
Checksum []byte `json:"value"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetKeys returns a list of flags comming with the challenge.
|
// GetKeys returns a list of flags comming with the challenge.
|
||||||
func (e Exercice) GetKeys() ([]Key, error) {
|
func (e Exercice) GetKeys() ([]Key, error) {
|
||||||
if rows, err := DBQuery("SELECT id_key, id_exercice, type, help, cksum FROM exercice_keys WHERE id_exercice = ?", e.Id); err != nil {
|
if rows, err := DBQuery("SELECT id_key, id_exercice, type, help, ignorecase, cksum FROM exercice_keys WHERE id_exercice = ?", e.Id); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
} else {
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
@ -32,7 +34,7 @@ func (e Exercice) GetKeys() ([]Key, error) {
|
||||||
var k Key
|
var k Key
|
||||||
k.IdExercice = e.Id
|
k.IdExercice = e.Id
|
||||||
|
|
||||||
if err := rows.Scan(&k.Id, &k.IdExercice, &k.Label, &k.Help, &k.Checksum); err != nil {
|
if err := rows.Scan(&k.Id, &k.IdExercice, &k.Label, &k.Help, &k.IgnoreCase, &k.Checksum); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
keys = append(keys, k)
|
keys = append(keys, k)
|
||||||
|
@ -52,25 +54,25 @@ func getHashedKey(raw_value string) [blake2b.Size]byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddRawKey creates and fills a new struct Key, from a non-hashed flag, and registers it into the database.
|
// AddRawKey creates and fills a new struct Key, from a non-hashed flag, and registers it into the database.
|
||||||
func (e Exercice) AddRawKey(name string, help string, raw_value string) (Key, error) {
|
func (e Exercice) AddRawKey(name string, help string, ignorecase bool, raw_value string) (Key, error) {
|
||||||
hash := getHashedKey(raw_value)
|
hash := getHashedKey(raw_value)
|
||||||
return e.AddKey(name, help, hash[:])
|
return e.AddKey(name, help, ignorecase, hash[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddKey creates and fills a new struct Key, from a hashed flag, and registers it into the database.
|
// AddKey creates and fills a new struct Key, from a hashed flag, and registers it into the database.
|
||||||
func (e Exercice) AddKey(name string, help string, checksum []byte) (Key, error) {
|
func (e Exercice) AddKey(name string, help string, ignorecase bool, checksum []byte) (Key, error) {
|
||||||
if res, err := DBExec("INSERT INTO exercice_keys (id_exercice, type, help, cksum) VALUES (?, ?, ?, ?)", e.Id, name, help, checksum); err != nil {
|
if res, err := DBExec("INSERT INTO exercice_keys (id_exercice, type, help, ignorecase, cksum) VALUES (?, ?, ?, ?)", e.Id, name, help, ignorecase, checksum); err != nil {
|
||||||
return Key{}, err
|
return Key{}, err
|
||||||
} else if kid, err := res.LastInsertId(); err != nil {
|
} else if kid, err := res.LastInsertId(); err != nil {
|
||||||
return Key{}, err
|
return Key{}, err
|
||||||
} else {
|
} else {
|
||||||
return Key{kid, e.Id, name, help, checksum}, nil
|
return Key{kid, e.Id, name, help, ignorecase, checksum}, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update applies modifications back to the database.
|
// Update applies modifications back to the database.
|
||||||
func (k Key) Update() (int64, error) {
|
func (k Key) Update() (int64, error) {
|
||||||
if res, err := DBExec("UPDATE exercice_keys SET id_exercice = ?, type = ?, help = ?, cksum = ? WHERE id_key = ?", k.IdExercice, k.Label, k.Help, k.Checksum, k.Id); err != nil {
|
if res, err := DBExec("UPDATE exercice_keys SET id_exercice = ?, type = ?, help = ?, ignorecase = ?, cksum = ? WHERE id_key = ?", k.IdExercice, k.Label, k.Help, k.Checksum, k.Id); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
} else if nb, err := res.RowsAffected(); err != nil {
|
} else if nb, err := res.RowsAffected(); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
|
|
Reference in a new issue