def self::read( source, recipient_key )
header = Saltpack::Header.parse( source, recipient_key )
self.log.debug( header )
if ( recipient = recipients.assoc(recipient_key.public_key) )
index = recipients.index( recipient ) or
raise "Recipient %p not present in the recipients list?!"
nonce = PAYLOAD_KEY_BOX_NONCE_PREFIX + [index].pack( 'Q>' )
box = RbNaCl::Box.new( ephemeral_pubkey, recipient_key )
payload_key = box.decrypt( nonce, recipient[1] )
else
ephemeral_beforenm = RbNaCl::Box.beforenm( ephemeral_pubkey, recipient_key ) or
raise "Failed to extract the ephemeral shared key."
recipients.each_with_index do |(_, encrypted_key), index|
nonce = self.payload_key_nonce( header.version, index )
payload_key = RbNaCl::Box.open_afternm( encrypted_key,
ephemeral_beforenm, nonce, RbNaCl::SecretBox.key_bytes )
break if payload_key
end
end
raise "Failed to extract the payload key" unless payload_key
sender_public = RbNaCl::SecretBox.new( payload_key ).
decrypt( SENDER_KEY_SECRETBOX_NONCE, sender_secretbox )
recipient_mac = Saltpack.calculate_recipient_hash( header_hash, index,
[sender_public, recipient_key],
[ephemeral_pubkey, recipient_key]
)
self.log.debug "recipient index: %p" % [ recipient_index ]
self.log.debug "sender key: %p" % [ sender_public ]
self.log.debug "payload key: %p" % [ payload_key ]
self.log.debug "mac key: %p" % [ mac_key ]
end