2023-05-26 01:59:09 +02:00
|
|
|
// Copyright 2023 wanderer <a_mirre at utb dot cz>
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
package localbreach
|
|
|
|
|
|
|
|
import (
|
2023-07-19 21:29:22 +02:00
|
|
|
"os"
|
2023-05-26 01:59:09 +02:00
|
|
|
"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) {
|
2023-07-19 21:29:22 +02:00
|
|
|
b, err := os.ReadFile(path)
|
2023-05-26 01:59:09 +02:00
|
|
|
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
|
|
|
|
}
|