diff options
author | evitayan <evitayan@google.com> | 2018-08-17 15:37:59 -0700 |
---|---|---|
committer | evitayan <evitayan@google.com> | 2018-09-17 17:33:14 -0700 |
commit | 6a806aab86785213ba83112224f08e4b98277f5b (patch) | |
tree | 9c1874a73160de5f4550f84a97f1693670db9d61 /tests/iketests/src/java/com/android | |
parent | 0d4bd0a36cd28f254020913dd5c54ef724f94821 (diff) | |
download | ike-6a806aab86785213ba83112224f08e4b98277f5b.tar.gz |
Encode Nonce Payload
This commit:
- Change encode method to take a ByteBuffer
- Change encodePayloadHeader to take a ByteBuffer
- Add abstract getPayloadLength method in IkePayload
- Add encodePayloads method in IkeMessage
- Implement encoding Nonce Payload
Bug: 112471425
Test: FrameworksIkeTests IkeNoncePayloadTest
Change-Id: I4faa4c5919af0f333afcf1c57615f8cc0930f74b
Diffstat (limited to 'tests/iketests/src/java/com/android')
3 files changed, 56 insertions, 2 deletions
diff --git a/tests/iketests/src/java/com/android/ike/ikev2/message/IkeMessageTest.java b/tests/iketests/src/java/com/android/ike/ikev2/message/IkeMessageTest.java index b7ecc3d6..05c59607 100644 --- a/tests/iketests/src/java/com/android/ike/ikev2/message/IkeMessageTest.java +++ b/tests/iketests/src/java/com/android/ike/ikev2/message/IkeMessageTest.java @@ -29,6 +29,8 @@ import com.android.ike.ikev2.exceptions.UnsupportedCriticalPayloadException; import org.junit.Before; import org.junit.Test; +import java.nio.ByteBuffer; + public final class IkeMessageTest { private static final String IKE_SA_INIT_RAW_PACKET = "8f54bf6d8b48e6e100000000000000002120220800000000" @@ -80,12 +82,18 @@ public final class IkeMessageTest { } @Override - byte[] encode(@PayloadType int nextPayload) { + protected void encodeToByteBuffer(@PayloadType int nextPayload, ByteBuffer byteBuffer) { throw new UnsupportedOperationException( "It is not supported to encode " + getTypeString()); } @Override + protected int getPayloadLength() { + throw new UnsupportedOperationException( + "It is not supported to get payload length of " + getTypeString()); + } + + @Override public String getTypeString() { return "Test Payload"; } diff --git a/tests/iketests/src/java/com/android/ike/ikev2/message/IkeNoncePayloadTest.java b/tests/iketests/src/java/com/android/ike/ikev2/message/IkeNoncePayloadTest.java new file mode 100644 index 00000000..a15507c5 --- /dev/null +++ b/tests/iketests/src/java/com/android/ike/ikev2/message/IkeNoncePayloadTest.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.ike.ikev2.message; + +import static org.junit.Assert.assertArrayEquals; + +import org.junit.Test; + +import java.nio.ByteBuffer; + +public final class IkeNoncePayloadTest { + + private static final String NONCE_PAYLOAD_RAW_HEX_STRING = + "29000024c39b7f368f4681b89fa9b7be6465abd7c5f68b6ed5d3b4c72cb4240eb5c46412"; + private static final String NONCE_DATA_RAW_HEX_STRING = + "c39b7f368f4681b89fa9b7be6465abd7c5f68b6ed5d3b4c72cb4240eb5c46412"; + + @IkePayload.PayloadType + private static final int NEXT_PAYLOAD_TYPE = IkePayload.PAYLOAD_TYPE_NOTIFY; + + @Test + public void testEncode() throws Exception { + byte[] inputPacket = TestUtils.hexStringToByteArray(NONCE_DATA_RAW_HEX_STRING); + IkeNoncePayload payload = new IkeNoncePayload(false, inputPacket); + + ByteBuffer byteBuffer = ByteBuffer.allocate(payload.getPayloadLength()); + payload.encodeToByteBuffer(NEXT_PAYLOAD_TYPE, byteBuffer); + + byte[] expectedNoncePayload = + TestUtils.hexStringToByteArray(NONCE_PAYLOAD_RAW_HEX_STRING); + assertArrayEquals(expectedNoncePayload, byteBuffer.array()); + } +} diff --git a/tests/iketests/src/java/com/android/ike/ikev2/message/IkeNotifyPayloadTest.java b/tests/iketests/src/java/com/android/ike/ikev2/message/IkeNotifyPayloadTest.java index 4968826c..382f04b1 100644 --- a/tests/iketests/src/java/com/android/ike/ikev2/message/IkeNotifyPayloadTest.java +++ b/tests/iketests/src/java/com/android/ike/ikev2/message/IkeNotifyPayloadTest.java @@ -33,7 +33,6 @@ public final class IkeNotifyPayloadTest { private static final int EXPECTED_NOTIFY_TYPE = IkeNotifyPayload.NOTIFY_TYPE_NAT_DETECTION_SOURCE_IP; - private static final int EXPECTED_SPI = 0; private static final int EXPECTED_NOTIFY_DATA_LEN = 20; private static final int POS_PROTOCOL_ID = 0; |