Class: I2P::KeyPair

Inherits:
Structure show all
Defined in:
lib/i2p/data/key_pair.rb,
lib/i2p/sdk.rb

Overview

**I2P key pair data structure.**

Constant Summary collapse

BYTESIZE =

minimum

Since:

  • 0.1.3

663

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Structure

#==, #eql?, parse, #to_base64

Constructor Details

#initialize(destination, private_key, signing_key) ⇒ KeyPair

Initializes a new key pair instance.

Parameters:

Since:

  • 0.1.3



25
26
27
28
29
# File 'lib/i2p/data/key_pair.rb', line 25

def initialize(destination, private_key, signing_key)
  @destination = destination
  @private_key = private_key
  @signing_key = signing_key
end

Instance Attribute Details

#destinationDestination

Returns:

Since:

  • 0.1.3



33
34
35
# File 'lib/i2p/data/key_pair.rb', line 33

def destination
  @destination
end

#private_keyPrivateKey

Returns:

Since:

  • 0.1.3



37
38
39
# File 'lib/i2p/data/key_pair.rb', line 37

def private_key
  @private_key
end

#signing_keySigningPrivateKey

Returns:

Since:

  • 0.1.3



41
42
43
# File 'lib/i2p/data/key_pair.rb', line 41

def signing_key
  @signing_key
end

Class Method Details

.read(input) ⇒ KeyPair

Reads a key pair from the given ‘input` stream.

Parameters:

  • input (IO, StringIO)

Returns:

Since:

  • 0.1.3



15
16
17
# File 'lib/i2p/data/key_pair.rb', line 15

def self.read(input)
  self.new(Destination.read(input), PrivateKey.read(input), SigningPrivateKey.read(input))
end

Instance Method Details

#sizeInteger Also known as: bytesize

Returns the byte size of this key pair.

Returns:

  • (Integer)

Since:

  • 0.1.3



47
48
49
# File 'lib/i2p/data/key_pair.rb', line 47

def size
  destination.size + private_key.size + signing_key.size
end

#to_javaObject

Returns an instance of the Java class ‘net.i2p.data.PrivateKeyFile`.

**This method only works with JRuby, not with MRI or YARV.**

Returns:

  • (Object)

Raises:

  • (NotImplementedError)

See Also:



108
109
110
# File 'lib/i2p/sdk.rb', line 108

def to_java
  raise NotImplementedError.new("#{self.class}#to_java") # TODO
end

#to_sString

Returns the binary string representation of this key pair.

Returns:

  • (String)

Since:

  • 0.1.3



56
57
58
59
60
61
62
63
# File 'lib/i2p/data/key_pair.rb', line 56

def to_s
  StringIO.open do |buffer|
    buffer.write(destination.to_s)
    buffer.write(private_key.to_s)
    buffer.write(signing_key.to_s)
    buffer.string
  end
end