creating new string key Init
This commit is contained in:
parent
a6ef43c637
commit
08433db912
|
@ -22,21 +22,26 @@ type StandardRicochetService struct {
|
||||||
|
|
||||||
// Init initializes a StandardRicochetService with the cryptographic key given
|
// Init initializes a StandardRicochetService with the cryptographic key given
|
||||||
// by filename.
|
// by filename.
|
||||||
func (srs *StandardRicochetService) Init(filename string) error {
|
func (srs *StandardRicochetService) InitFromKeyFile(filename string) error {
|
||||||
srs.ricochet = new(Ricochet)
|
|
||||||
srs.ricochet.Init()
|
|
||||||
|
|
||||||
pemData, err := ioutil.ReadFile(filename)
|
pemData, err := ioutil.ReadFile(filename)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("Could not setup ricochet service: could not read private key")
|
return errors.New("Could not setup ricochet service: could not read private key")
|
||||||
}
|
}
|
||||||
|
return srs.InitFromKey(pemData)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Init initializes a StandardRicochetService with the cryptographic key
|
||||||
|
func (srs *StandardRicochetService) InitFromKey(pemData []byte) error {
|
||||||
|
srs.ricochet = new(Ricochet)
|
||||||
|
srs.ricochet.Init()
|
||||||
|
|
||||||
block, _ := pem.Decode(pemData)
|
block, _ := pem.Decode(pemData)
|
||||||
if block == nil || block.Type != "RSA PRIVATE KEY" {
|
if block == nil || block.Type != "RSA PRIVATE KEY" {
|
||||||
return errors.New("Could not setup ricochet service: no valid PEM data found")
|
return errors.New("Could not setup ricochet service: no valid PEM data found")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
srs.privateKey, err = x509.ParsePKCS1PrivateKey(block.Bytes)
|
srs.privateKey, err = x509.ParsePKCS1PrivateKey(block.Bytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("Could not setup ricochet service: could not parse private key")
|
return errors.New("Could not setup ricochet service: could not parse private key")
|
||||||
|
|
Loading…
Reference in New Issue