Class: I2P::Certificate
- Defined in:
- lib/i2p/data/certificate.rb,
lib/i2p/sdk.rb
Overview
**I2P certificate data structure.**
Defines a certificate that can be attached to various I2P structures, such as ‘RouterIdentity` and `Destination`, allowing routers and clients to help manage denial of service attacks and the network utilization.
Constant Summary collapse
- TYPE_NULL =
Null certificate
0
- TYPE_HASHCASH =
Hashcash certificate
1
- TYPE_HIDDEN =
Hidden certificate
2
- TYPE_SIGNED =
Signed certificate
3
- TYPE_MULTIPLE =
4
- LENGTH_SIGNED_WITH_HASH =
TODO
nil
Instance Attribute Summary collapse
Class Method Summary collapse
-
.read(input) ⇒ Certificate
Reads a certificate from the given ‘input` stream.
Instance Method Summary collapse
-
#initialize(type = TYPE_NULL, payload = String.new) ⇒ Certificate
constructor
Initializes a new certificate instance.
-
#size ⇒ Integer
(also: #bytesize)
Returns the byte size of this certificate.
-
#to_java ⇒ Object
Returns an instance of the Java class ‘net.i2p.data.Certificate`.
-
#to_s ⇒ String
Returns the binary string representation of this certificate.
Methods inherited from Structure
#==, #eql?, parse, #to_base64
Constructor Details
#initialize(type = TYPE_NULL, payload = String.new) ⇒ Certificate
Initializes a new certificate instance.
45 46 47 |
# File 'lib/i2p/data/certificate.rb', line 45 def initialize(type = TYPE_NULL, payload = String.new) @type, @payload = type.to_i, payload end |
Instance Attribute Details
#payload ⇒ String
38 39 40 |
# File 'lib/i2p/data/certificate.rb', line 38 def payload @payload end |
#type ⇒ Integer
34 35 36 |
# File 'lib/i2p/data/certificate.rb', line 34 def type @type end |
Class Method Details
.read(input) ⇒ Certificate
Reads a certificate from the given ‘input` stream.
25 26 27 28 29 30 |
# File 'lib/i2p/data/certificate.rb', line 25 def self.read(input) type = input.read(1).unpack('c').first length = input.read(2).unpack('n').first payload = length.zero? ? String.new : input.read(length) self.new(type, payload) end |
Instance Method Details
#size ⇒ Integer Also known as: bytesize
Returns the byte size of this certificate.
53 54 55 |
# File 'lib/i2p/data/certificate.rb', line 53 def size 1 + 2 + (payload ? payload.size : 0) end |
#to_java ⇒ Object
Returns an instance of the Java class ‘net.i2p.data.Certificate`.
**This method only works with JRuby, not with MRI or YARV.**
30 31 32 |
# File 'lib/i2p/sdk.rb', line 30 def to_java I2P::SDK::Certificate.new(type.to_i, payload.to_s.to_java_bytes) end |
#to_s ⇒ String
Returns the binary string representation of this certificate.
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/i2p/data/certificate.rb', line 62 def to_s StringIO.open do |buffer| buffer.write([type].pack('c')) if payload && !payload.empty? buffer.write([payload.size].pack('n')) buffer.write(payload.to_s) else buffer.write([0].pack('n')) end buffer.string end end |