Class: ActiveCipherStorage::Adapters::S3Adapter::StreamingDecryptor

Inherits:
Object
  • Object
show all
Includes:
KeyUtils
Defined in:
lib/active_cipher_storage/adapters/s3_adapter.rb

Overview

Accumulates bytes from a streaming S3 response, parses ACS frames as they arrive, and yields each decrypted plaintext chunk. Frame layout: seq(4) + iv(12) + ct_len(4) + ciphertext(ct_len) + auth_tag(16).

Constant Summary collapse

FRAME_PREFIX_SIZE =

20 bytes to determine ct_len

4 + Format::IV_SIZE + 4

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ StreamingDecryptor

Returns a new instance of StreamingDecryptor.



177
178
179
180
181
182
183
# File 'lib/active_cipher_storage/adapters/s3_adapter.rb', line 177

def initialize(config)
  @config      = config
  @buffer      = "".b
  @dek         = nil
  @header_done = false
  @done        = false
end

Instance Method Details

#finish!Object



192
193
194
195
196
# File 'lib/active_cipher_storage/adapters/s3_adapter.rb', line 192

def finish!
  raise Errors::InvalidFormat, "Stream ended before final frame" unless @done
ensure
  zero_bytes!(@dek)
end

#push(bytes, &block) ⇒ Object



185
186
187
188
189
190
# File 'lib/active_cipher_storage/adapters/s3_adapter.rb', line 185

def push(bytes, &block)
  return if @done
  @buffer += bytes.b
  try_parse_header unless @header_done
  drain_frames(&block) if @header_done
end