Class: Ronin::Payloads::Encoders::Pipeline
- Inherits:
-
Object
- Object
- Ronin::Payloads::Encoders::Pipeline
- Defined in:
- lib/ronin/payloads/encoders/pipeline.rb
Overview
Represents a pipeline of payload encoders.
Instance Attribute Summary collapse
-
#encoders ⇒ Array<Encoder>
readonly
The encoders in the pipeline.
Instance Method Summary collapse
-
#<<(new_encoder) ⇒ self
Adds a new encoder to the encoder pipeline.
-
#[](id_or_index) ⇒ Encoder?
Fetches an encoder at the given index or by the encoder's
id
. -
#each {|encoder| ... } ⇒ Enumerator
Enumerates over each encoder in the pipeline.
-
#empty? ⇒ Boolean
Determines whether the pipeline is empty and has no encoders in it.
-
#encode(payload) ⇒ String
Encodes the payload using the encoder pipeline.
-
#initialize(encoders = []) ⇒ Pipeline
constructor
Initializes the encoder pipeline.
-
#validate ⇒ Object
Validates all encoders in the pipeline.
Constructor Details
#initialize(encoders = []) ⇒ Pipeline
Initializes the encoder pipeline.
47 48 49 |
# File 'lib/ronin/payloads/encoders/pipeline.rb', line 47 def initialize(encoders=[]) @encoders = encoders end |
Instance Attribute Details
#encoders ⇒ Array<Encoder> (readonly)
The encoders in the pipeline.
39 40 41 |
# File 'lib/ronin/payloads/encoders/pipeline.rb', line 39 def encoders @encoders end |
Instance Method Details
#<<(new_encoder) ⇒ self
Adds a new encoder to the encoder pipeline.
59 60 61 62 |
# File 'lib/ronin/payloads/encoders/pipeline.rb', line 59 def <<(new_encoder) @encoders << new_encoder return self end |
#[](id_or_index) ⇒ Encoder?
Fetches an encoder at the given index or by the encoder's id
.
111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/ronin/payloads/encoders/pipeline.rb', line 111 def [](id_or_index) case id_or_index when String id = id_or_index @encoders.find { |encoder| encoder.class_id == id } else index = id_or_index @encoders[index] end end |
#each {|encoder| ... } ⇒ Enumerator
Enumerates over each encoder in the pipeline.
85 86 87 |
# File 'lib/ronin/payloads/encoders/pipeline.rb', line 85 def each(&block) @encoders.each(&block) end |
#empty? ⇒ Boolean
Determines whether the pipeline is empty and has no encoders in it.
69 70 71 |
# File 'lib/ronin/payloads/encoders/pipeline.rb', line 69 def empty? @encoders.empty? end |
#encode(payload) ⇒ String
Encodes the payload using the encoder pipeline.
136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/ronin/payloads/encoders/pipeline.rb', line 136 def encode(payload) encoded_payload = payload @encoders.each do |encoder| unless (encoded_payload = encoder.encode(encoded_payload)) raise(BadEncoder,"no result was returned by the encoder: #{encoder.inspect}") end end return encoded_payload end |
#validate ⇒ Object
Validates all encoders in the pipeline.
98 99 100 |
# File 'lib/ronin/payloads/encoders/pipeline.rb', line 98 def validate each(&:validate) end |