@Test public void testserializeAADSeqInvalid() { exception.expect(IllegalArgumentException.class); OSSerializer.serializeAAD(version, ctx.getAlg(), -5, ctx.getSenderId(), options); }
public static byte[] serializeAAD(int version, AlgorithmID algorithm, int requestSeq, byte[] requestSenderId, OptionSet options) { if (version == CoAP.VERSION) { if (requestSeq > -1) { if (algorithm != null) { if (options != null) { CBORObject algorithms = CBORObject.NewArray(); algorithms.Add(algorithm.AsCBOR()); CBORObject aad = CBORObject.NewArray(); aad.Add(version); aad.Add(algorithms); aad.Add(requestSenderId); aad.Add(processPartialIV(requestSeq)); aad.Add(CBORObject.FromObject(Bytes.EMPTY)); return aad.EncodeToBytes(); } else { LOGGER.error(ErrorDescriptions.OPTIONSET_NULL); throw new NullPointerException(ErrorDescriptions.OPTIONSET_NULL); } } else { LOGGER.error(ErrorDescriptions.ALGORITHM_NOT_DEFINED); throw new NullPointerException(ErrorDescriptions.ALGORITHM_NOT_DEFINED); } } else { LOGGER.error(ErrorDescriptions.SEQ_NBR_INVALID); throw new IllegalArgumentException(ErrorDescriptions.SEQ_NBR_INVALID); } } else { LOGGER.error(ErrorDescriptions.WRONG_VERSION_NBR); throw new IllegalArgumentException(ErrorDescriptions.WRONG_VERSION_NBR); } }
OSSerializer { public static byte[] serializeAAD(int version, AlgorithmID algorithm, int requestSeq, byte[] requestSenderId, OptionSet options) { if (version == CoAP.VERSION) { if (requestSeq > -1) { if (algorithm != null) { if (options != null) { CBORObject algorithms = CBORObject.NewArray(); algorithms.Add(algorithm.AsCBOR()); CBORObject aad = CBORObject.NewArray(); aad.Add(version); aad.Add(algorithms); aad.Add(requestSenderId); aad.Add(processPartialIV(requestSeq)); aad.Add(CBORObject.FromObject(Bytes.EMPTY)); return aad.EncodeToBytes(); } else { LOGGER.error(ErrorDescriptions.OPTIONSET_NULL); throw new NullPointerException(ErrorDescriptions.OPTIONSET_NULL); } } else { LOGGER.error(ErrorDescriptions.ALGORITHM_NOT_DEFINED); throw new NullPointerException(ErrorDescriptions.ALGORITHM_NOT_DEFINED); } } else { LOGGER.error(ErrorDescriptions.SEQ_NBR_INVALID); throw new IllegalArgumentException(ErrorDescriptions.SEQ_NBR_INVALID); } } else { LOGGER.error(ErrorDescriptions.WRONG_VERSION_NBR); throw new IllegalArgumentException(ErrorDescriptions.WRONG_VERSION_NBR); } } }
OSSerializer { public static byte[] serializeAAD(int version, AlgorithmID algorithm, int requestSeq, byte[] requestSenderId, OptionSet options) { if (version == CoAP.VERSION) { if (requestSeq > -1) { if (algorithm != null) { if (options != null) { CBORObject algorithms = CBORObject.NewArray(); algorithms.Add(algorithm.AsCBOR()); CBORObject aad = CBORObject.NewArray(); aad.Add(version); aad.Add(algorithms); aad.Add(requestSenderId); aad.Add(processPartialIV(requestSeq)); aad.Add(CBORObject.FromObject(Bytes.EMPTY)); return aad.EncodeToBytes(); } else { LOGGER.error(ErrorDescriptions.OPTIONSET_NULL); throw new NullPointerException(ErrorDescriptions.OPTIONSET_NULL); } } else { LOGGER.error(ErrorDescriptions.ALGORITHM_NOT_DEFINED); throw new NullPointerException(ErrorDescriptions.ALGORITHM_NOT_DEFINED); } } else { LOGGER.error(ErrorDescriptions.SEQ_NBR_INVALID); throw new IllegalArgumentException(ErrorDescriptions.SEQ_NBR_INVALID); } } else { LOGGER.error(ErrorDescriptions.WRONG_VERSION_NBR); throw new IllegalArgumentException(ErrorDescriptions.WRONG_VERSION_NBR); } }  }
OSSerializer { public static byte[] serializeAAD(int version, AlgorithmID algorithm, int requestSeq, byte[] requestSenderId, OptionSet options) { if (version == CoAP.VERSION) { if (requestSeq > -1) { if (algorithm != null) { if (options != null) { CBORObject algorithms = CBORObject.NewArray(); algorithms.Add(algorithm.AsCBOR()); CBORObject aad = CBORObject.NewArray(); aad.Add(version); aad.Add(algorithms); aad.Add(requestSenderId); aad.Add(processPartialIV(requestSeq)); aad.Add(CBORObject.FromObject(Bytes.EMPTY)); return aad.EncodeToBytes(); } else { LOGGER.error(ErrorDescriptions.OPTIONSET_NULL); throw new NullPointerException(ErrorDescriptions.OPTIONSET_NULL); } } else { LOGGER.error(ErrorDescriptions.ALGORITHM_NOT_DEFINED); throw new NullPointerException(ErrorDescriptions.ALGORITHM_NOT_DEFINED); } } else { LOGGER.error(ErrorDescriptions.SEQ_NBR_INVALID); throw new IllegalArgumentException(ErrorDescriptions.SEQ_NBR_INVALID); } } else { LOGGER.error(ErrorDescriptions.WRONG_VERSION_NBR); throw new IllegalArgumentException(ErrorDescriptions.WRONG_VERSION_NBR); } }  static byte[] serializeConfidentialData(OptionSet options, byte[] payload, int realCode); static byte[] serializeAAD(int version, AlgorithmID algorithm, int requestSeq, byte[] requestSenderId, OptionSet options); static byte[] nonceGeneration(byte[] partialIV, byte[] senderID, byte[] commonIV, int nonceLength); static byte[] leftPaddingZeroes(byte[] paddMe, int zeros); static byte[] processPartialIV(int value); static byte[] stripZeroes(byte[] in); }
OSSerializer { public static byte[] serializeAAD(int version, AlgorithmID algorithm, int requestSeq, byte[] requestSenderId, OptionSet options) { if (version == CoAP.VERSION) { if (requestSeq > -1) { if (algorithm != null) { if (options != null) { CBORObject algorithms = CBORObject.NewArray(); algorithms.Add(algorithm.AsCBOR()); CBORObject aad = CBORObject.NewArray(); aad.Add(version); aad.Add(algorithms); aad.Add(requestSenderId); aad.Add(processPartialIV(requestSeq)); aad.Add(CBORObject.FromObject(Bytes.EMPTY)); return aad.EncodeToBytes(); } else { LOGGER.error(ErrorDescriptions.OPTIONSET_NULL); throw new NullPointerException(ErrorDescriptions.OPTIONSET_NULL); } } else { LOGGER.error(ErrorDescriptions.ALGORITHM_NOT_DEFINED); throw new NullPointerException(ErrorDescriptions.ALGORITHM_NOT_DEFINED); } } else { LOGGER.error(ErrorDescriptions.SEQ_NBR_INVALID); throw new IllegalArgumentException(ErrorDescriptions.SEQ_NBR_INVALID); } } else { LOGGER.error(ErrorDescriptions.WRONG_VERSION_NBR); throw new IllegalArgumentException(ErrorDescriptions.WRONG_VERSION_NBR); } }  static byte[] serializeConfidentialData(OptionSet options, byte[] payload, int realCode); static byte[] serializeAAD(int version, AlgorithmID algorithm, int requestSeq, byte[] requestSenderId, OptionSet options); static byte[] nonceGeneration(byte[] partialIV, byte[] senderID, byte[] commonIV, int nonceLength); static byte[] leftPaddingZeroes(byte[] paddMe, int zeros); static byte[] processPartialIV(int value); static byte[] stripZeroes(byte[] in);  }