hashdb

package module
v0.0.0-...-394b203 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2017 License: BSD-2-Clause Imports: 10 Imported by: 0

README

hashdb

Package hashdb provides a database for hex-based hashes.

Sample

HashDatabase

  // Create a new database in memory.
  db, err := OpenDatabase(":memory:", md5.New(), 10)
  if err != nil {
      return err
  }
  
  // Add new entry
  err = db.Put("MT1992")
  if err != nil {
      return err
  }
  
  // Get entry
  password, err := db.GetExact("5f87e0f786e60b554ec522ce85ddc930")
  if err != nil {
      return err
  }

HashMix

  // Create a new hash-mix in memory.
  mix, err := OpenMix(":memory:", 1)
  if err != nil {
      return err
  }
  
  // Add new entry
  err = mix.Put("MT1992")
  if err != nil {
      return err
  }
  
  // Get entry
  passMap, err := mix.GetMD5("5f87e0f786e60b554ec522ce85ddc930") // or mix.GetMD5("5f87e0f")
  if err != nil {
      return err
  }

Documentation

Overview

Package hashdb provides a database for hex-based hashes.

This package needs kuroneko's sqlite3 library (https://github.com/kuroneko/gosqlite3).

HashMix Sample

// Create a new hash-mix in memory.
mix, err := OpenMix(":memory:", 10)
if err != nil {
  return err
}

// Add new entry
err = mix.Put("MT1992")
if err != nil {
  return err
}

// Get entry
passwordMap, err := mix.GetMD5("5f87e0f786e60b554ec522ce85ddc930") // or mix.GetMD5("5f87e0f")
if err != nil {
  return err
}

HashDB Sample

// Create a new database in memory.
db, err := OpenDatabase(":memory:", md5.New(), 10)
if err != nil {
  return err
}

// Add new entry
err = db.Put("MT1992")
if err != nil {
  return err
}

// Get entry
password, err := db.GetExact("5f87e0f786e60b554ec522ce85ddc930")
if err != nil {
  return err
}

Index

Constants

View Source
const HexAlphabet = "0123456789abcdef"

Variables

View Source
var (
	ErrCreatingDatabase       = errors.New("Error while creating Database.")
	ErrCreatingTable          = errors.New("Error while creating Table.")
	ErrCreatingIndex          = errors.New("Error while creating Index.")
	ErrInitExactHandlerFailed = errors.New("Exact-handler initialization failed.")
	ErrInitLikeHandlerFailed  = errors.New("Like-handler initialization failed.")
	ErrInitPutHandlerFailed   = errors.New("Put-handler initialization failed.")
	ErrHashTooShort           = errors.New("The length of the hash is too short.")
	ErrDatastoreNotFound      = errors.New("The requested datastore was not found.")
	ErrDirectoryNotFound      = errors.New("The directory doesn't exist.")
	ErrPasswordMissing        = errors.New("Password parameter is empty.")
	ErrWrongHashFormat        = errors.New("Hash-format is wrong.")
)

Functions

This section is empty.

Types

type Datastore

type Datastore struct {
	// contains filtered or unexported fields
}

func OpenDatastore

func OpenDatastore(name string, maxGetHandler int) (ds *Datastore, err error)

OpenDatastore creates a new Datastore and binds it to the backend database.

func (*Datastore) Count

func (ds *Datastore) Count() (int64, error)

Count returns the number of entries in the datastore.

func (*Datastore) GetExact

func (ds *Datastore) GetExact(hash string) (password string, err error)

GetExact returns the password for the supplied hash. No fuzzy search!

func (*Datastore) GetLike

func (ds *Datastore) GetLike(request *GetRequest)

GetLike returns all matching passwords for the supplied hash.

hash LIKE ?

func (*Datastore) Put

func (ds *Datastore) Put(hash string, password string) *PutResponse

Put creates a new entry in the database.

type GetRequest

type GetRequest struct {
	// contains filtered or unexported fields
}

type GetResponse

type GetResponse struct {
	// contains filtered or unexported fields
}

type HashDB

type HashDB struct {
	// contains filtered or unexported fields
}

func OpenDatabase

func OpenDatabase(directory string, hashFunc hash.Hash, maxGetHandler int) (db *HashDB, err error)

OpenDatabase creates or opens a new HashDB instance. directory accepts a valid directory or ":memory:" if you want the database only in RAM.

func (*HashDB) Count

func (db *HashDB) Count() (result int64, err error)

Count returns the number of entries in the database.

func (*HashDB) GetExact

func (db *HashDB) GetExact(hash string) (password string, err error)

GetExact searches for the hash in the database. The hash parameter has to be lower-case.

func (*HashDB) GetLike

func (db *HashDB) GetLike(hash string) (map[string]string, error)

GetLike searches in the database for a hash that contains the supplied hash-part.

func (*HashDB) Put

func (db *HashDB) Put(password string, resultChan chan *PutResponse)

Put stores a new hash in the database. The hash is stored as lower-case.

type HashMix

type HashMix struct {
	// contains filtered or unexported fields
}

func OpenMix

func OpenMix(directory string, maxPerDatabaseHandler int) (hm *HashMix, err error)

OpenMix creates a new HashMix instance.

func (*HashMix) Count

func (hm *HashMix) Count() (md5_count int64, sha1_count int64, err error)

Count returns the number of entries in the databases.

func (*HashMix) GetMD5

func (hm *HashMix) GetMD5(hash string) (map[string]string, error)

GetMD5 tries to find the MD5-hash in the database.

func (*HashMix) GetSHA1

func (hm *HashMix) GetSHA1(hash string) (map[string]string, error)

GetSHA1 tries to find the SHA1-hash in the database.

func (*HashMix) Put

func (hm *HashMix) Put(password string, responseChan chan *PutResponse)

Put stores the new password in the MD5 and SHA1 database. The responseChan gets two messages - one for each HashDB.

type LookupTable

type LookupTable map[string]*Datastore

type PutRequest

type PutRequest struct {
	// contains filtered or unexported fields
}

type PutResponse

type PutResponse struct {
	// contains filtered or unexported fields
}

Directories

Path Synopsis
This http-"server" understands three different requests: - /md5?q=AAAAAAA -> searches the MD5 hash in the database - /sha1?q=BBBBBB -> searches the SHA1 hash in the database - /new?p=newPassword -> adds the password to the database Before the server is started the first time the "db" folder has to be created: - `mkdir db db/md5 db/sha1`
This http-"server" understands three different requests: - /md5?q=AAAAAAA -> searches the MD5 hash in the database - /sha1?q=BBBBBB -> searches the SHA1 hash in the database - /new?p=newPassword -> adds the password to the database Before the server is started the first time the "db" folder has to be created: - `mkdir db db/md5 db/sha1`

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL