mirror of
https://github.com/go-i2p/i2pkeys.git
synced 2025-06-17 20:29:56 -04:00
Separate out generate address function and make it's SAM port configurable
This commit is contained in:
@ -70,7 +70,7 @@ func Test_NewI2PAddrFromString(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Address with .i2p suffix", func(t *testing.T) { //CHECK
|
t.Run("Address with .i2p suffix", func(t *testing.T) { // CHECK
|
||||||
addr, err := NewI2PAddrFromString(validI2PAddrB64 + ".i2p")
|
addr, err := NewI2PAddrFromString(validI2PAddrB64 + ".i2p")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("NewI2PAddrFromString failed for address with .i2p suffix: '%v'", err)
|
t.Fatalf("NewI2PAddrFromString failed for address with .i2p suffix: '%v'", err)
|
||||||
@ -169,15 +169,15 @@ func Test_KeyGenerationAndHandling(t *testing.T) {
|
|||||||
t.Fatalf("Failed to generate new I2P keys: %v", err)
|
t.Fatalf("Failed to generate new I2P keys: %v", err)
|
||||||
}
|
}
|
||||||
t.Run("LoadKeysIncompat", func(t *testing.T) {
|
t.Run("LoadKeysIncompat", func(t *testing.T) {
|
||||||
//extract keys
|
// extract keys
|
||||||
addr := keys.Address
|
addr := keys.Address
|
||||||
fmt.Println(addr)
|
fmt.Println(addr)
|
||||||
|
|
||||||
//both := removeNewlines(keys.Both)
|
// both := removeNewlines(keys.Both)
|
||||||
both := keys.Both
|
both := keys.Both
|
||||||
fmt.Println(both)
|
fmt.Println(both)
|
||||||
|
|
||||||
//FORMAT TO LOAD: (Address, Both)
|
// FORMAT TO LOAD: (Address, Both)
|
||||||
addrload := addr.Base64() + "\n" + both
|
addrload := addr.Base64() + "\n" + both
|
||||||
|
|
||||||
r := strings.NewReader(addrload)
|
r := strings.NewReader(addrload)
|
||||||
@ -187,9 +187,8 @@ func Test_KeyGenerationAndHandling(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if loadedKeys.Address != keys.Address {
|
if loadedKeys.Address != keys.Address {
|
||||||
//fmt.Printf("loadedKeys.Address md5hash: '%s'\n keys.Address md5hash: '%s'\n", getMD5Hash(string(loadedKeys.Address)), getMD5Hash(string(keys.Address)))
|
// fmt.Printf("loadedKeys.Address md5hash: '%s'\n keys.Address md5hash: '%s'\n", getMD5Hash(string(loadedKeys.Address)), getMD5Hash(string(keys.Address)))
|
||||||
t.Errorf("LoadKeysIncompat returned incorrect address. Got '%s', want '%s'", loadedKeys.Address, keys.Address)
|
t.Errorf("LoadKeysIncompat returned incorrect address. Got '%s', want '%s'", loadedKeys.Address, keys.Address)
|
||||||
|
|
||||||
}
|
}
|
||||||
if loadedKeys.Both != keys.Both {
|
if loadedKeys.Both != keys.Both {
|
||||||
t.Errorf("LoadKeysIncompat returned incorrect pair. Got '%s'\nwant '%s'\n", loadedKeys.Both, keys.Both)
|
t.Errorf("LoadKeysIncompat returned incorrect pair. Got '%s'\nwant '%s'\n", loadedKeys.Both, keys.Both)
|
||||||
@ -199,7 +198,6 @@ func Test_KeyGenerationAndHandling(t *testing.T) {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
expected := keys.Address.Base64() + "\n" + keys.Both
|
expected := keys.Address.Base64() + "\n" + keys.Both
|
||||||
|
@ -128,6 +128,7 @@ func StoreKeysIncompat(k I2PKeys, w io.Writer) error {
|
|||||||
log.WithField("keys", k).Debug("Keys stored successfully")
|
log.WithField("keys", k).Debug("Keys stored successfully")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func StoreKeys(k I2PKeys, r string) error {
|
func StoreKeys(k I2PKeys, r string) error {
|
||||||
log.WithField("filename", r).Debug("Storing keys to file")
|
log.WithField("filename", r).Debug("Storing keys to file")
|
||||||
if _, err := os.Stat(r); err != nil {
|
if _, err := os.Stat(r); err != nil {
|
||||||
@ -190,7 +191,7 @@ func (k I2PKeys) PrivateKey() crypto.PrivateKey {
|
|||||||
_, err := pk.Sign(rand.Reader, []byte("nonsense"), crypto.Hash(0))
|
_, err := pk.Sign(rand.Reader, []byte("nonsense"), crypto.Hash(0))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Warn("Error in private key signature")
|
log.WithError(err).Warn("Error in private key signature")
|
||||||
//TODO: Elgamal, P256, P384, P512, GOST? keys?
|
// TODO: Elgamal, P256, P384, P512, GOST? keys?
|
||||||
}
|
}
|
||||||
return pk
|
return pk
|
||||||
}
|
}
|
||||||
@ -225,4 +226,3 @@ func (k I2PKeys) HostnameEntry(hostname string, opts crypto.SignerOpts) (string,
|
|||||||
}
|
}
|
||||||
return string(sig), nil
|
return string(sig), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
log.go
4
log.go
@ -4,9 +4,7 @@ import (
|
|||||||
"github.com/go-i2p/logger"
|
"github.com/go-i2p/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var log *logger.Logger
|
||||||
log *logger.Logger
|
|
||||||
)
|
|
||||||
|
|
||||||
func InitializeI2PKeysLogger() {
|
func InitializeI2PKeysLogger() {
|
||||||
logger.InitializeGoI2PLogger()
|
logger.InitializeGoI2PLogger()
|
||||||
|
5
new.go
5
new.go
@ -9,8 +9,9 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var DefaultSAMAddress = "127.0.0.1:7656"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defaultSAMAddress = "127.0.0.1:7656"
|
|
||||||
defaultTimeout = 30 * time.Second
|
defaultTimeout = 30 * time.Second
|
||||||
maxResponseSize = 4096
|
maxResponseSize = 4096
|
||||||
|
|
||||||
@ -30,7 +31,7 @@ type samClient struct {
|
|||||||
// newSAMClient creates a new SAM client with optional configuration
|
// newSAMClient creates a new SAM client with optional configuration
|
||||||
func newSAMClient(options ...func(*samClient)) *samClient {
|
func newSAMClient(options ...func(*samClient)) *samClient {
|
||||||
client := &samClient{
|
client := &samClient{
|
||||||
addr: defaultSAMAddress,
|
addr: DefaultSAMAddress,
|
||||||
timeout: defaultTimeout,
|
timeout: defaultTimeout,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user