This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ArgumentParser | |
import Crypto | |
struct Hsh: ParsableCommand { | |
static var configuration = CommandConfiguration( | |
subcommands: [Md5.self, Sha1.self] | |
) | |
} | |
struct Md5: ParsableCommand { | |
@Argument(help: "String to calculate MD5 hash from") | |
var value: String | |
mutating func run() { | |
let data = value.data(using: .utf8) | |
let hash = Insecure.MD5.hash(data: data!) | |
print(hash.map { String(format: "%02hhx", $0) }.joined()) | |
} | |
} | |
struct Sha1: ParsableCommand { | |
@Argument(help: "String to calculate Sha1 hash from") | |
var value: String | |
mutating func run() { | |
let data = value.data(using: .utf8) | |
let hash = Insecure.SHA1.hash(data: data!) | |
print(hash.map { String(format: "%02hhx", $0) }.joined()) | |
} | |
} | |
Hsh.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment