Class: Ji2p::Control::Keypair
Defined Under Namespace
Modules: Old
Instance Attribute Summary collapse
-
#cert ⇒ Object
Returns the value of attribute cert.
-
#dest ⇒ Object
Returns the value of attribute dest.
-
#priv ⇒ Object
Returns the value of attribute priv.
-
#pub ⇒ Object
Returns the value of attribute pub.
-
#spriv ⇒ Object
Returns the value of attribute spriv.
-
#spub ⇒ Object
Returns the value of attribute spub.
Class Method Summary collapse
Instance Method Summary collapse
- #createSession(opts = Java::JavaUtil::Properties.new) ⇒ Object
- #destination ⇒ Object
-
#initialize(cert, pub, priv, spub, spriv, data) ⇒ Keypair
constructor
A new instance of Keypair.
- #inputstream ⇒ Object
- #padding ⇒ Object
- #padding_size ⇒ Object
- #private_key_format ⇒ Object
- #write_file(f) ⇒ Object
Constructor Details
#initialize(cert, pub, priv, spub, spriv, data) ⇒ Keypair
Returns a new instance of Keypair.
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/ji2p/control/keypair.rb', line 65 def initialize cert,pub,priv,spub,spriv,data @cert = cert @pub = pub @priv = priv @spub = spub @spriv = spriv @data = data @dest = Ji2p::Control::Dest.new @dest.setKeypair self end |
Instance Attribute Details
#cert ⇒ Object
Returns the value of attribute cert.
42 43 44 |
# File 'lib/ji2p/control/keypair.rb', line 42 def cert @cert end |
#dest ⇒ Object
Returns the value of attribute dest.
42 43 44 |
# File 'lib/ji2p/control/keypair.rb', line 42 def dest @dest end |
#priv ⇒ Object
Returns the value of attribute priv.
42 43 44 |
# File 'lib/ji2p/control/keypair.rb', line 42 def priv @priv end |
#pub ⇒ Object
Returns the value of attribute pub.
42 43 44 |
# File 'lib/ji2p/control/keypair.rb', line 42 def pub @pub end |
#spriv ⇒ Object
Returns the value of attribute spriv.
42 43 44 |
# File 'lib/ji2p/control/keypair.rb', line 42 def spriv @spriv end |
#spub ⇒ Object
Returns the value of attribute spub.
42 43 44 |
# File 'lib/ji2p/control/keypair.rb', line 42 def spub @spub end |
Class Method Details
.generate!(sig = DEFAULT_SIG_TYPE) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/ji2p/control/keypair.rb', line 44 def self.generate! sig=DEFAULT_SIG_TYPE ost = StringIO.new c = I2PClientFactory.createClient c.createDestination(ost.to_outputstream, sig) keystream = StringIO.new ost.string load_from_stream! keystream end |
.load_from_stream!(keystream) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ji2p/control/keypair.rb', line 52 def self.load_from_stream! keystream c = I2PClientFactory.createClient s = c.createSession(keystream.to_inputstream, Java::JavaUtil::Properties.new) pub = s.myDestination.getPublicKey spub = s.myDestination.getSigningPublicKey priv = s.decryptionKey spriv = s.privateKey # This will be equal to the content of a # net.i2p.data.PrivateKeyFile cert = s.myDestination.getCertificate new cert,pub,priv,spub,spriv,keystream.string end |
Instance Method Details
#createSession(opts = Java::JavaUtil::Properties.new) ⇒ Object
85 86 87 88 89 |
# File 'lib/ji2p/control/keypair.rb', line 85 def createSession opts=Java::JavaUtil::Properties.new c = I2PClientFactory.createClient @session = c.createSession(inputstream, opts) @session end |
#destination ⇒ Object
81 82 83 |
# File 'lib/ji2p/control/keypair.rb', line 81 def destination @dest end |
#inputstream ⇒ Object
76 77 78 79 |
# File 'lib/ji2p/control/keypair.rb', line 76 def inputstream stream = StringIO.new @data stream.to_inputstream end |
#padding ⇒ Object
100 101 102 |
# File 'lib/ji2p/control/keypair.rb', line 100 def padding SecureRandom.random_bytes(padding_size).to_java_bytes end |
#padding_size ⇒ Object
95 96 97 98 |
# File 'lib/ji2p/control/keypair.rb', line 95 def padding_size ((Java::NetI2pData::SigningPublicKey::KEYSIZE_BYTES - @spub.length) + (Java::NetI2pData::PublicKey::KEYSIZE_BYTES - @pub.length)) end |
#private_key_format ⇒ Object
91 92 93 |
# File 'lib/ji2p/control/keypair.rb', line 91 def private_key_format @data end |
#write_file(f) ⇒ Object
104 105 106 107 108 |
# File 'lib/ji2p/control/keypair.rb', line 104 def write_file f f = File.open(f, 'wb') unless f.is_a? File f.write(@data) f.close end |