Skip to content

Commit

Permalink
make NewHasher functions compatible with NewHasherFunc
Browse files Browse the repository at this point in the history
  • Loading branch information
tomi77 committed Jul 15, 2019
1 parent 3b168f3 commit 3b82256
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 63 deletions.
72 changes: 9 additions & 63 deletions hasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,69 +65,15 @@ type NewHasherFunc func(iterations *int, salt *string, hashedPassword *[]byte) H
var (
// Internal map of registered hashers
registeredHashers = map[string]NewHasherFunc{
TypePlain: NewHasherFunc(func(iterations *int, salt *string, hashedPassword *[]byte) Hasher {
return &PlainHasher{
Iter: iterations,
Salt: salt,
Password: hashedPassword,
}
}),
TypeMD5: NewHasherFunc(func(iterations *int, salt *string, hashedPassword *[]byte) Hasher {
return &MD5Hasher{
Iter: iterations,
Salt: salt,
Password: hashedPassword,
}
}),
TypeSHA1: NewHasherFunc(func(iterations *int, salt *string, hashedPassword *[]byte) Hasher {
return &SHA1Hasher{
Iter: iterations,
Salt: salt,
Password: hashedPassword,
}
}),
TypeSHA224: NewHasherFunc(func(iterations *int, salt *string, hashedPassword *[]byte) Hasher {
return &SHA224Hasher{
Iter: iterations,
Salt: salt,
Password: hashedPassword,
}
}),
TypeSHA256: NewHasherFunc(func(iterations *int, salt *string, hashedPassword *[]byte) Hasher {
return &SHA256Hasher{
Iter: iterations,
Salt: salt,
Password: hashedPassword,
}
}),
TypeSHA384: NewHasherFunc(func(iterations *int, salt *string, hashedPassword *[]byte) Hasher {
return &SHA384Hasher{
Iter: iterations,
Salt: salt,
Password: hashedPassword,
}
}),
TypeSHA512: NewHasherFunc(func(iterations *int, salt *string, hashedPassword *[]byte) Hasher {
return &SHA512Hasher{
Iter: iterations,
Salt: salt,
Password: hashedPassword,
}
}),
TypeSHA512_224: NewHasherFunc(func(iterations *int, salt *string, hashedPassword *[]byte) Hasher {
return &SHA512_224Hasher{
Iter: iterations,
Salt: salt,
Password: hashedPassword,
}
}),
TypeSHA512_256: NewHasherFunc(func(iterations *int, salt *string, hashedPassword *[]byte) Hasher {
return &SHA512_256Hasher{
Iter: iterations,
Salt: salt,
Password: hashedPassword,
}
}),
TypePlain: NewHasherFunc(NewPlainHasher),
TypeMD5: NewHasherFunc(NewMD5Hasher),
TypeSHA1: NewHasherFunc(NewSHA1Hasher),
TypeSHA224: NewHasherFunc(NewSHA224Hasher),
TypeSHA256: NewHasherFunc(NewSHA256Hasher),
TypeSHA384: NewHasherFunc(NewSHA384Hasher),
TypeSHA512: NewHasherFunc(NewSHA512Hasher),
TypeSHA512_224: NewHasherFunc(NewSHA512_224Hasher),
TypeSHA512_256: NewHasherFunc(NewSHA512_256Hasher),
}
)

Expand Down
9 changes: 9 additions & 0 deletions md5_hasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ type MD5Hasher struct {
Password *[]byte
}

// NewMD5Hasher returns a new MD5 hasher instance
func NewMD5Hasher(iterations *int, salt *string, hashedPassword *[]byte) Hasher {
return &MD5Hasher{
Iter: iterations,
Salt: salt,
Password: hashedPassword,
}
}

// Code returns internal MD5 hasher code
func (h MD5Hasher) Code() string {
return TypeMD5
Expand Down
9 changes: 9 additions & 0 deletions plain_hasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ type PlainHasher struct {
Password *[]byte
}

// NewPlainHasher returns a new plain hasher instance
func NewPlainHasher(iterations *int, salt *string, hashedPassword *[]byte) Hasher {
return &PlainHasher{
Iter: iterations,
Salt: salt,
Password: hashedPassword,
}
}

// Code returns internal plain hasher code
func (h PlainHasher) Code() string {
return TypePlain
Expand Down
9 changes: 9 additions & 0 deletions sha1_hasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ type SHA1Hasher struct {
Password *[]byte
}

// NewSHA1Hasher returns a new SHA1 hasher instance
func NewSHA1Hasher(iterations *int, salt *string, hashedPassword *[]byte) Hasher {
return &SHA1Hasher{
Iter: iterations,
Salt: salt,
Password: hashedPassword,
}
}

// Code returns internal SHA-224 hasher code
func (h SHA1Hasher) Code() string {
return TypeSHA1
Expand Down
9 changes: 9 additions & 0 deletions sha224_hasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ type SHA224Hasher struct {
Password *[]byte
}

// NewSHA224Hasher returns a new plain hasher instance
func NewSHA224Hasher(iterations *int, salt *string, hashedPassword *[]byte) Hasher {
return &SHA224Hasher{
Iter: iterations,
Salt: salt,
Password: hashedPassword,
}
}

// Code returns internal SHA-224 hasher code
func (h SHA224Hasher) Code() string {
return TypeSHA224
Expand Down
9 changes: 9 additions & 0 deletions sha256_hasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ type SHA256Hasher struct {
Password *[]byte
}

// NewSHA256Hasher returns a new plain hasher instance
func NewSHA256Hasher(iterations *int, salt *string, hashedPassword *[]byte) Hasher {
return &SHA256Hasher{
Iter: iterations,
Salt: salt,
Password: hashedPassword,
}
}

// Code returns internal SHA-224 hasher code
func (h SHA256Hasher) Code() string {
return TypeSHA256
Expand Down
9 changes: 9 additions & 0 deletions sha384_hasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ type SHA384Hasher struct {
Password *[]byte
}

// NewSHA384Hasher returns a new plain hasher instance
func NewSHA384Hasher(iterations *int, salt *string, hashedPassword *[]byte) Hasher {
return &SHA384Hasher{
Iter: iterations,
Salt: salt,
Password: hashedPassword,
}
}

// Code returns internal SHA-384 hasher code
func (h SHA384Hasher) Code() string {
return TypeSHA384
Expand Down
9 changes: 9 additions & 0 deletions sha512_224_hasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ type SHA512_224Hasher struct {
Password *[]byte
}

// NewSHA512_224Hasher returns a new plain hasher instance
func NewSHA512_224Hasher(iterations *int, salt *string, hashedPassword *[]byte) Hasher {
return &SHA512_224Hasher{
Iter: iterations,
Salt: salt,
Password: hashedPassword,
}
}

// Code returns internal SHA-512/224 hasher code
func (h SHA512_224Hasher) Code() string {
return TypeSHA512_224
Expand Down
9 changes: 9 additions & 0 deletions sha512_256_hasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ type SHA512_256Hasher struct {
Password *[]byte
}

// NewSHA512_256Hasher returns a new plain hasher instance
func NewSHA512_256Hasher(iterations *int, salt *string, hashedPassword *[]byte) Hasher {
return &SHA512_256Hasher{
Iter: iterations,
Salt: salt,
Password: hashedPassword,
}
}

// Code returns internal SHA-512/256 hasher code
func (h SHA512_256Hasher) Code() string {
return TypeSHA512_256
Expand Down
9 changes: 9 additions & 0 deletions sha512_hasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ type SHA512Hasher struct {
Password *[]byte
}

// NewSHA512Hasher returns a new plain hasher instance
func NewSHA512Hasher(iterations *int, salt *string, hashedPassword *[]byte) Hasher {
return &SHA512Hasher{
Iter: iterations,
Salt: salt,
Password: hashedPassword,
}
}

// Code returns internal SHA-512 hasher code
func (h SHA512Hasher) Code() string {
return TypeSHA512
Expand Down

0 comments on commit 3b82256

Please sign in to comment.