More golint fixing in utils

This commit is contained in:
Sarah Jamie Lewis 2018-01-08 11:01:23 -08:00
parent 1a2fb40d91
commit 4b700d4223
2 changed files with 13 additions and 7 deletions

View File

@ -10,13 +10,16 @@ import (
) )
const ( const (
// InvalidPrivateKeyFileError is a library error, thrown when the given key file fials to load
InvalidPrivateKeyFileError = Error("InvalidPrivateKeyFileError") InvalidPrivateKeyFileError = Error("InvalidPrivateKeyFileError")
RICOCHET_KEY_SIZE = 1024
// RicochetKeySize - tor onion services currently use rsa key sizes of 1024 bits
RicochetKeySize = 1024
) )
// Generate a private key for use // GeneratePrivateKey generates a new private key for use
func GeneratePrivateKey() (*rsa.PrivateKey, error) { func GeneratePrivateKey() (*rsa.PrivateKey, error) {
privateKey, err := rsa.GenerateKey(rand.Reader, RICOCHET_KEY_SIZE) privateKey, err := rsa.GenerateKey(rand.Reader, RicochetKeySize)
if err != nil { if err != nil {
return nil, errors.New("Could not generate key: " + err.Error()) return nil, errors.New("Could not generate key: " + err.Error())
} }
@ -34,7 +37,7 @@ func LoadPrivateKeyFromFile(filename string) (*rsa.PrivateKey, error) {
return ParsePrivateKey(pemData) return ParsePrivateKey(pemData)
} }
// Convert a private key string to a usable private key // ParsePrivateKey Convert a private key string to a usable private key
func ParsePrivateKey(pemData []byte) (*rsa.PrivateKey, error) { func ParsePrivateKey(pemData []byte) (*rsa.PrivateKey, error) {
block, _ := pem.Decode(pemData) block, _ := pem.Decode(pemData)
if block == nil || block.Type != "RSA PRIVATE KEY" { if block == nil || block.Type != "RSA PRIVATE KEY" {
@ -44,7 +47,7 @@ func ParsePrivateKey(pemData []byte) (*rsa.PrivateKey, error) {
return x509.ParsePKCS1PrivateKey(block.Bytes) return x509.ParsePKCS1PrivateKey(block.Bytes)
} }
// turn a private key into storable string // PrivateKeyToString turns a private key into storable string
func PrivateKeyToString(privateKey *rsa.PrivateKey) string { func PrivateKeyToString(privateKey *rsa.PrivateKey) string {
privateKeyBlock := pem.Block{ privateKeyBlock := pem.Block{
Type: "RSA PRIVATE KEY", Type: "RSA PRIVATE KEY",

View File

@ -7,9 +7,12 @@ import (
) )
const ( const (
// CannotResolveLocalTCPAddressError is thrown when a local ricochet connection has the wrong format.
CannotResolveLocalTCPAddressError = Error("CannotResolveLocalTCPAddressError") CannotResolveLocalTCPAddressError = Error("CannotResolveLocalTCPAddressError")
CannotDialLocalTCPAddressError = Error("CannotDialLocalTCPAddressError") // CannotDialLocalTCPAddressError is thrown when a connection to a local ricochet address fails.
CannotDialRicochetAddressError = Error("CannotDialRicochetAddressError") CannotDialLocalTCPAddressError = Error("CannotDialLocalTCPAddressError")
// CannotDialRicochetAddressError is thrown when a connection to a ricochet address fails.
CannotDialRicochetAddressError = Error("CannotDialRicochetAddressError")
) )
// NetworkResolver allows a client to resolve various hostnames to connections // NetworkResolver allows a client to resolve various hostnames to connections