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
|
||||
// by filename.
|
||||
func (srs *StandardRicochetService) Init(filename string) error {
|
||||
srs.ricochet = new(Ricochet)
|
||||
srs.ricochet.Init()
|
||||
|
||||
func (srs *StandardRicochetService) InitFromKeyFile(filename string) error {
|
||||
pemData, err := ioutil.ReadFile(filename)
|
||||
|
||||
if err != nil {
|
||||
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)
|
||||
if block == nil || block.Type != "RSA PRIVATE KEY" {
|
||||
return errors.New("Could not setup ricochet service: no valid PEM data found")
|
||||
}
|
||||
|
||||
var err error
|
||||
srs.privateKey, err = x509.ParsePKCS1PrivateKey(block.Bytes)
|
||||
if err != nil {
|
||||
return errors.New("Could not setup ricochet service: could not parse private key")
|
||||
|
|
Loading…
Reference in New Issue