Exemplo n.º 1
0
/*! \brief  Parse key descriptor.

    \warning  Encoded data is modified during parsing.
    \warning  In case of an error, throws either ByteSeqException or
              IPMPDataException.

    \param  encoded     input, encoded data.

    \returns  Key descriptor.
*/
KeyDescriptor IPMPDataParser::ParseKeyDescriptor(ByteSeq& encoded) {
  ByteSeq keyBody = encoded.GetBytes((UInt32T)(encoded.GetSizeOfInstance(0)));
  return KeyDescriptor(keyBody);
}
Exemplo n.º 2
0
/*! \brief  Parse IPMP data message, call handling function and return it's
            response.

    \warning  Encoded data is modified during parsing.
    \warning  Response can be empty, depending on whether any response is
              needed and whether an error occured during the processing.

    \param  sender    input, sender's code.
    \param  encoded   input, encoded message.
    \param  agent     input, IPMP agent which will handle parsed message.
    \param  resp      output, response message data.

    \returns  Boolean indicating success or failure.
*/
bool IPMPDataParser::ParseMessage(const Bit32T& sender, ByteSeq& encoded,
    IPMPAgent* agent, ByteSeq& resp) {
  try {
    ByteT tag = encoded.GetByte();
    ByteSeq data(encoded.GetBytes((UInt32T)(encoded.GetSizeOfInstance(0xfffffff))));
    switch (tag) {
    case 0x01:
      //  Opaque data.
      if (agent->HandleOpaqueIPMPData(sender, ParseOpaqueData(data), resp) == false) {
        return false;
      }
      break;
    case 0x08:
      //  Rights data.
      if (agent->HandleRightsIPMPData(sender, ParseRightsData(data), resp) == false) {
        return false;
      }
      break;
    case 0x09:
      //  Secure container.
      if (agent->HandleSecureContainerIPMPData(sender, ParseSecureContainer(data), resp) == false) {
        return false;
      }
      break;
    case 0x0c:
      //  Init authentication.
      if (agent->HandleInitAuthenticationIPMPData(sender, ParseInitAuthentication(data), resp) == false) {
        return false;
      }
      break;
    case 0x0d:
      //  Mutual authentication.
      if (agent->HandleMutualAuthenticationIPMPData(sender, ParseMutualAuthentication(data), resp) == false) {
        return false;
      }
      break;
    case 0x17:
      //  Can process.
      if (agent->HandleCanProcessIPMPData(sender, ParseCanProcess(data), resp) == false) {
        return false;
      }
      break;
    case 0x0e:
      //  User query.
      if (agent->HandleUserQueryIPMPData(sender, ParseUserQueryData(data), resp) == false) {
        return false;
      }
      break;
    case 0x0f:
      //  User response.
      if (agent->HandleUserQueryResponseIPMPData(sender, ParseUserQueryResponseData(data), resp) == false) {
        return false;
      }
      break;
    default:
      return false;
    }
    return true;
  }
  catch (ByteSeqException) {
    return false;
  }
  catch (IPMPDataException) {
    return false;
  }
  catch (IPMPDataParserException) {
    return false;
  }
//  catch (...) {
//    return false;
//  }
}