def encrypt(header, frame)
      raise RLPxSessionError, 'not ready' unless ready?
      raise ArgumentError, 'invalid header length' unless header.size == 16
      raise ArgumentError, 'invalid frame padding' unless frame.size % 16 == 0

      header_ciphertext = aes_enc header
      raise RLPxSessionError unless header_ciphertext.size == header.size
      header_mac = egress_mac(Utils.sxor(mac_enc(egress_mac[0,16]), header_ciphertext))[0,16]

      frame_ciphertext = aes_enc frame
      raise RLPxSessionError unless frame_ciphertext.size == frame.size
      fmac_seed = egress_mac frame_ciphertext
      frame_mac = egress_mac(Utils.sxor(mac_enc(egress_mac[0,16]), fmac_seed[0,16]))[0,16]

      header_ciphertext + header_mac + frame_ciphertext + frame_mac
    end
def encrypt(header, frame)
      raise RLPxSessionError, 'not ready' unless ready?
      raise ArgumentError, 'invalid header length' unless header.size == 16
      raise ArgumentError, 'invalid frame padding' unless frame.size % 16 == 0

      header_ciphertext = aes_enc header
      raise RLPxSessionError unless header_ciphertext.size == header.size
      header_mac = egress_mac(Utils.sxor(mac_enc(egress_mac[0,16]), header_ciphertext))[0,16]

      frame_ciphertext = aes_enc frame
      raise RLPxSessionError unless frame_ciphertext.size == frame.size
      fmac_seed = egress_mac frame_ciphertext
      frame_mac = egress_mac(Utils.sxor(mac_enc(egress_mac[0,16]), fmac_seed[0,16]))[0,16]

      header_ciphertext + header_mac + frame_ciphertext + frame_mac
    end
Frame Handling