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.



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

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

Instance Method Details

#finish!Object



206
207
208
209
210
211
# File 'lib/active_cipher_storage/adapters/s3_adapter.rb', line 206

def finish!
  raise Errors::InvalidFormat, "Stream ended before final frame" unless @done
  raise Errors::InvalidFormat, "Trailing bytes after final frame" unless @buffer.empty?
ensure
  zero_bytes!(@dek)
end

#push(bytes, &block) ⇒ Object



194
195
196
197
198
199
200
201
202
203
204
# File 'lib/active_cipher_storage/adapters/s3_adapter.rb', line 194

def push(bytes, &block)
  if @done
    raise Errors::InvalidFormat, "Trailing bytes after final frame" unless bytes.empty?

    return
  end

  @buffer += bytes.b
  try_parse_header unless @header_done
  drain_frames(&block) if @header_done
end