Documentation ¶
Overview ¶
Package `pwnedpass` is a Go package for querying a local instance of Troy Hunt's Pwned Passwords database.
Index ¶
- Constants
- Variables
- type OfflineDatabase
- func (od *OfflineDatabase) Close() error
- func (od *OfflineDatabase) Pwned(hash [20]byte) (frequency int, err error)
- func (od *OfflineDatabase) Scan(startPrefix, endPrefix [3]byte, hash []byte, cb func(frequency uint16) bool) error
- func (od *OfflineDatabase) ServeHTTP(w http.ResponseWriter, r *http.Request)
Constants ¶
const ( // DatabaseFilename is the default path to the database. DatabaseFilename = "pwned-passwords.bin" // IndexSegmentSize is the exact size of the index segment in bytes. IndexSegmentSize = 256 << 16 << 3 // exactly 256^3 MB // DataSegmentOffset indicates the byte offset in the database where // the data segment begins. DataSegmentOffset = IndexSegmentSize )
Variables ¶
var ( // FirstPrefix is the very first prefix in the dataset. It is intended // to be used as a parameter to Scan. FirstPrefix = [3]byte{0x00, 0x00, 0x00} // LastPrefix is the very last prefix in the dataset. It is intended // to be used as a parameter to Scan. LastPrefix = [3]byte{0xFF, 0xFF, 0xFF} )
Functions ¶
This section is empty.
Types ¶
type OfflineDatabase ¶
type OfflineDatabase struct {
// contains filtered or unexported fields
}
An OfflineDatabase is a client for querying Pwned Passwords locally.
func NewOfflineDatabase ¶
func NewOfflineDatabase(dbFile string) (*OfflineDatabase, error)
NewOfflineDatabase opens a new OfflineDatabase using the data in the given database file.
func (*OfflineDatabase) Close ¶
func (od *OfflineDatabase) Close() error
Close frees resources associated with the database.
func (*OfflineDatabase) Pwned ¶
func (od *OfflineDatabase) Pwned(hash [20]byte) (frequency int, err error)
Pwned checks how frequently the given hash is included in the Pwned Passwords database.
Pwned will only return an error in the case of an invalid database file. Hashes that are not found in the database will return a frequency of 0 and a nil error.
func (*OfflineDatabase) Scan ¶
func (od *OfflineDatabase) Scan(startPrefix, endPrefix [3]byte, hash []byte, cb func(frequency uint16) bool) error
Scan iterates through all hashes between startPrefix and endPrefix (inclusive). Iteration begins at the first hash with a prefix of startPrefix and continues until one of these conditions is met:
- the last hash with a prefix of endPrefix has been reached,
- the callback returns "true" to indicate a stop is requested, or 3) the end of the hash database is reached.
The binary-encoded hash is written into the hash slice argument, which must be at least 20 bytes long (providing a smaller slice will result in a panic).
Scan will only return an error in the case of an invalid database file.
func (*OfflineDatabase) ServeHTTP ¶
func (od *OfflineDatabase) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements the http.Handler interface by approximating the online Pwned Password V2 API. The following routes are available:
/pwnedpassword/password /pwnedpassword/hash /range/ABCDE
Their behavior is very similar to that of the online equivalent; the same documentation should apply.