Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Allow the direct checking of public keys #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ func main() {
&cli.BoolFlag{
Name: "debug",
},
&cli.BoolFlag{
Name: "public-key",
},
},
Action: func(c *cli.Context) error {
args := c.Args().Slice()
Expand Down Expand Up @@ -58,27 +61,33 @@ func main() {

file := args[0]

var privateKey []byte
var inKey []byte
var err error
if file == "-" {
buff := bytes.NewBuffer(nil)
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
buff.WriteString(scanner.Text() + "\n")
}
privateKey = buff.Bytes()
inKey = buff.Bytes()
} else {
privateKey, err = ioutil.ReadFile(args[0])
inKey, err = ioutil.ReadFile(args[0])
if err != nil {
logger.Fatalf("File cannot be read: %s", err)
return nil
}
}

publicKey, err := parser.PublicKey(privateKey)
if err != nil {
logger.Fatalf("Error computing public key: %s", err)
var publicKey []byte
if ! c.Bool("public-key") {
publicKey, err = parser.PublicKey(inKey)
if err != nil {
logger.Fatalf("Error computing public key: %s", err)
}
} else {
publicKey = inKey
}

result, err := client.Lookup(version, publicKey)
if err != nil {
logger.Fatalf("Error looking up public key: %s", err)
Expand Down