Skip to content

Commit

Permalink
Md5 (#26)
Browse files Browse the repository at this point in the history
* Add md5 hash

* go fmt
  • Loading branch information
joohoi authored May 13, 2021
1 parent 3a6ef5b commit f107aa2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/pencode/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func main() {
if err != nil {
fmt.Printf(" [!] %s\n", err)
}
fmt.Print(string(output))
fmt.Println(string(output))
}

func readInput() string {
Expand Down
1 change: 1 addition & 0 deletions pkg/pencode/encoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var availableEncoders = map[string]Encoder{
"hexdecode": HexDecoder{},
"jsonescape": JSONEscaper{},
"jsonunescape": JSONUnescaper{},
"md5": MD5Hasher{},
"unicodedecode": UnicodeDecode{},
"unicodeencodeall": UnicodeEncodeAll{},
"urlencode": URLEncoder{},
Expand Down
16 changes: 16 additions & 0 deletions pkg/pencode/md5.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package pencode

import (
"crypto/md5"
"fmt"
)

type MD5Hasher struct{}

func (m MD5Hasher) Encode(input []byte) ([]byte, error) {
return []byte(fmt.Sprintf("%x", md5.Sum(input))), nil
}

func (m MD5Hasher) HelpText() string {
return "MD5 sum"
}
4 changes: 2 additions & 2 deletions pkg/pencode/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func hasTemplate(name string) (bool, error) {
}

type Template struct {
Data []byte
Data []byte
Keyword string
}

Expand All @@ -44,4 +44,4 @@ func (t Template) Encode(input []byte) ([]byte, error) {

func (t Template) HelpText() string {
return "Replaces string #PAYLOAD# in content of a file that has .tmpl extension."
}
}

0 comments on commit f107aa2

Please sign in to comment.