pcmt/modules/localbreach/breach.go
leo 11de8de558
All checks were successful
continuous-integration/drone/push Build is passing
go: add local breach data schema
2023-05-26 01:59:09 +02:00

51 lines
1.2 KiB
Go

// Copyright 2023 wanderer <a_mirre at utb dot cz>
// SPDX-License-Identifier: AGPL-3.0-only
package localbreach
import (
"io/ioutil"
"time"
"gopkg.in/yaml.v2"
)
type BreachDataSchema struct {
Name string `yaml:"name" validate:"required,name"`
Time time.Time `yaml:"time"`
IsVerified bool `yaml:"isVerified"`
ContainsPasswords bool `yaml:"containsPasswds"`
ContainsHashes bool `yaml:"containsHashes"`
HashType string `yaml:"hashType"`
HashSalted bool `yaml:"hashSalted"`
ContainsUsernames bool `yaml:"containsUsernames"`
ContainsEmails bool `yaml:"containsEmails"`
Data any `yaml:"data"`
}
// Load loads local breach data.
func Load(path string) (*BreachDataSchema, error) {
b, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
localBreach, err := loadLocalBreach(b)
if err != nil {
return nil, err
}
return localBreach, nil
}
func loadLocalBreach(b []byte) (*BreachDataSchema, error) {
localBreach := new(BreachDataSchema)
err := yaml.Unmarshal(b, localBreach)
if err != nil {
return nil, err
}
return localBreach, nil
}