Ejemplo n.º 1
0
 /**
  * Skips the integrity pad and pad length fields.
  *
  * @param rawMessage - Byte array holding whole message data.
  * @param offset - Offset to integrity pad.
  * @return Offset to Auth Code
  * @throws IndexOutOfBoundsException when message is corrupted and pad length does not appear
  *     after integrity pad or length is incorrect.
  */
 private int skipIntegrityPAD(byte[] rawMessage, int offset) throws IndexOutOfBoundsException {
   int skip = 0;
   while (TypeConverter.byteToInt(rawMessage[offset + skip]) == 0xff) {
     ++skip;
   }
   int length = TypeConverter.byteToInt(rawMessage[offset + skip]);
   if (length != skip) {
     throw new IndexOutOfBoundsException("Message is corrupted.");
   }
   offset += skip + 2; // skip pad length and next header fields
   if (offset >= rawMessage.length) {
     throw new IndexOutOfBoundsException("Message is corrupted.");
   }
   return offset;
 }
Ejemplo n.º 2
0
  /**
   * Decodes OEM IANA.
   *
   * @param rawMessage - Byte array holding whole message data.
   * @return OEM IANA number.
   */
  private int decodeOEMIANA(byte[] rawMessage) {
    byte[] oemIANA = new byte[4];

    System.arraycopy(rawMessage, 3, oemIANA, 0, 3);
    oemIANA[3] = 0;

    return TypeConverter.littleEndianByteArrayToInt(oemIANA);
  }
Ejemplo n.º 3
0
  @Override
  protected int decodePayloadLength(byte[] rawData, int offset) {
    byte[] payloadLength = new byte[4];
    System.arraycopy(rawData, offset, payloadLength, 0, 2);
    payloadLength[2] = 0;
    payloadLength[3] = 0;

    return TypeConverter.littleEndianByteArrayToInt(payloadLength);
  }
Ejemplo n.º 4
0
 public static PayloadType decodePayloadType(byte payloadType) throws IllegalArgumentException {
   return PayloadType.parseInt(
       TypeConverter.intToByte(payloadType & TypeConverter.intToByte(0x3f)));
 }
Ejemplo n.º 5
0
 /**
  * Decodes second bit of Payload Type.
  *
  * @param payloadType
  * @return True if payload is authenticated, false otherwise.
  */
 public boolean decodeAuthentication(byte payloadType) {
   return !((payloadType & TypeConverter.intToByte(0x40)) == 0);
 }
Ejemplo n.º 6
0
 /**
  * Decodes first bit of Payload Type.
  *
  * @param payloadType
  * @return True if payload is encrypted, false otherwise.
  */
 private boolean decodeEncryption(byte payloadType) {
   return !((payloadType & TypeConverter.intToByte(0x80)) == 0);
 }