From 3b8225604c03b388a4ff56433083dc4df5d2f25b Mon Sep 17 00:00:00 2001 From: Tomasz Jakub Rup Date: Mon, 15 Jul 2019 09:02:01 +0200 Subject: [PATCH] make NewHasher functions compatible with NewHasherFunc --- hasher.go | 72 ++++++-------------------------------------- md5_hasher.go | 9 ++++++ plain_hasher.go | 9 ++++++ sha1_hasher.go | 9 ++++++ sha224_hasher.go | 9 ++++++ sha256_hasher.go | 9 ++++++ sha384_hasher.go | 9 ++++++ sha512_224_hasher.go | 9 ++++++ sha512_256_hasher.go | 9 ++++++ sha512_hasher.go | 9 ++++++ 10 files changed, 90 insertions(+), 63 deletions(-) diff --git a/hasher.go b/hasher.go index 980ba61..eefd22e 100644 --- a/hasher.go +++ b/hasher.go @@ -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), } ) diff --git a/md5_hasher.go b/md5_hasher.go index 7c4e027..a64aa00 100644 --- a/md5_hasher.go +++ b/md5_hasher.go @@ -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 diff --git a/plain_hasher.go b/plain_hasher.go index a652534..d49cc6f 100644 --- a/plain_hasher.go +++ b/plain_hasher.go @@ -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 diff --git a/sha1_hasher.go b/sha1_hasher.go index d4a693b..aebec3b 100644 --- a/sha1_hasher.go +++ b/sha1_hasher.go @@ -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 diff --git a/sha224_hasher.go b/sha224_hasher.go index 43f7528..8a764be 100644 --- a/sha224_hasher.go +++ b/sha224_hasher.go @@ -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 diff --git a/sha256_hasher.go b/sha256_hasher.go index 174ebf5..28f2831 100644 --- a/sha256_hasher.go +++ b/sha256_hasher.go @@ -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 diff --git a/sha384_hasher.go b/sha384_hasher.go index a527f36..aaabbe3 100644 --- a/sha384_hasher.go +++ b/sha384_hasher.go @@ -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 diff --git a/sha512_224_hasher.go b/sha512_224_hasher.go index 26a2c77..db74484 100644 --- a/sha512_224_hasher.go +++ b/sha512_224_hasher.go @@ -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 diff --git a/sha512_256_hasher.go b/sha512_256_hasher.go index 259949d..79b029f 100644 --- a/sha512_256_hasher.go +++ b/sha512_256_hasher.go @@ -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 diff --git a/sha512_hasher.go b/sha512_hasher.go index 2fad29a..afbe3a8 100644 --- a/sha512_hasher.go +++ b/sha512_hasher.go @@ -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