summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-09-04 17:14:49 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-09-04 17:14:49 +0200
commit6e1c21c6c4062918b303fedf610322ea2968392e (patch)
treee624b411bb2cac0a5e3e8d27d2ac9ccd6355472c
parent12416ef3ea7ade91cadf06444fb6720cbf69f37e (diff)
error
-rw-r--r--main.go13
1 files changed, 8 insertions, 5 deletions
diff --git a/main.go b/main.go
index e773b98..dac211b 100644
--- a/main.go
+++ b/main.go
@@ -87,23 +87,26 @@ func factor(N *big.Int) (*big.Int, *big.Int) {
return nil, nil
}
-func pubKey(f string) rsa.PublicKey {
+func pubKey(f string) (*rsa.PublicKey, error) {
file, err := ioutil.ReadFile(f)
if err != nil {
- log.Fatal(err)
+ return nil, err
}
block, _ := pem.Decode(file)
key, err := x509.ParsePKCS1PrivateKey(block.Bytes)
if err != nil {
- log.Fatal(err)
+ return nil, err
}
- return key.PublicKey
+ return &key.PublicKey, nil
}
func main() {
- pub := pubKey("test.key")
+ pub, err := pubKey("test.key")
+ if err != nil {
+ log.Fatal(err)
+ }
fmt.Println(factor(pub.N))
}