def load(msg, id = nil)
      msg = @serializer.load(msg)
      sig = Signature.from_data(msg['signature'])
      certs = @store.get_signer(msg['id'])
      raise MissingCertificate.new("Could not find a certificate for signer #{msg['id']}") unless certs

      certs = [ certs ] unless certs.respond_to?(:any?)
      raise InvalidSignature.new("Failed signature check for signer #{msg['id']}") unless certs.any? { |c| sig.match?(c) }

      data = msg['data']
      if data && msg['encrypted']
        cert, key = @store.get_receiver(id)
        raise MissingCertificate.new("Could not find a certificate for #{id.inspect}") unless cert
        raise MissingPrivateKey.new("Could not find a private key for #{id.inspect}") unless key
        data = EncryptedDocument.from_data(data).decrypted_data(key, cert)
      end
      @serializer.load(data) if data
    end
def load(msg, id = nil)
      msg = @serializer.load(msg)
      sig = Signature.from_data(msg['signature'])
      certs = @store.get_signer(msg['id'])
      raise MissingCertificate.new("Could not find a certificate for signer #{msg['id']}") unless certs

      certs = [ certs ] unless certs.respond_to?(:any?)
      raise InvalidSignature.new("Failed signature check for signer #{msg['id']}") unless certs.any? { |c| sig.match?(c) }

      data = msg['data']
      if data && msg['encrypted']
        cert, key = @store.get_receiver(id)
        raise MissingCertificate.new("Could not find a certificate for #{id.inspect}") unless cert
        raise MissingPrivateKey.new("Could not find a private key for #{id.inspect}") unless key
        data = EncryptedDocument.from_data(data).decrypted_data(key, cert)
      end
      @serializer.load(data) if data
    end
Decrypt, authorize signature, and unserialize message
 Use x.509 certificate store for decrypting and validating signature

 === Parameters
 msg(String):: Serialized and optionally encrypted object using MessagePack or JSON
 id(String|nil):: Optional identifier of source of data for use
   in determining who is the receiver

 === Return
 (Object):: Unserialized object

 === Raise
 MissingCertificate:: If could not find certificate for message signer or receiver
 MissingPrivateKey:: If could not find private key for message receiver
 InvalidSignature:: If message signature check failed for message