Skip to content

Commit

Permalink
Update kotlin-mbedtls v1.17.2
Browse files Browse the repository at this point in the history
  • Loading branch information
szysas committed Aug 21, 2023
1 parent c30ecf2 commit c4b9670
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
4 changes: 2 additions & 2 deletions coap-mbedtls/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ description = "coap-mbedtls"

dependencies {
api(project(":coap-core"))
api("io.github.open-coap:kotlin-mbedtls:1.16.0")
api("io.github.open-coap:kotlin-mbedtls:1.17.2")

testImplementation(project(":coap-netty"))
testImplementation("io.github.open-coap:kotlin-mbedtls-netty:1.16.0")
testImplementation("io.github.open-coap:kotlin-mbedtls-netty:1.17.2")

testImplementation(testFixtures(project(":coap-core")))
testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.3")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
public class DtlsTransportContext {
public static final TransportContext.Key<Map<String, String>> DTLS_AUTHENTICATION = new TransportContext.Key<>(Collections.emptyMap());
public static final TransportContext.Key<String> DTLS_PEER_CERTIFICATE_SUBJECT = new TransportContext.Key<>(null);
public static final TransportContext.Key<byte[]> DTLS_CID = new TransportContext.Key<>(null);

public static TransportContext toTransportContext(DtlsSessionContext dtlsSessionContext) {
if (dtlsSessionContext.equals(DtlsSessionContext.EMPTY)) {
Expand All @@ -33,6 +34,9 @@ public static TransportContext toTransportContext(DtlsSessionContext dtlsSession
if (dtlsSessionContext.getPeerCertificateSubject() != null) {
dtlsContext = dtlsContext.with(DTLS_PEER_CERTIFICATE_SUBJECT, dtlsSessionContext.getPeerCertificateSubject());
}
if (dtlsSessionContext.getCid() != null) {
dtlsContext = dtlsContext.with(DTLS_CID, dtlsSessionContext.getCid());
}

return dtlsContext;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (C) 2022-2023 java-coap contributors (https://github.com/open-coap/java-coap)
* SPDX-License-Identifier: Apache-2.0
* 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 org.opencoap.transport.mbedtls;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.opencoap.transport.mbedtls.DtlsTransportContext.DTLS_AUTHENTICATION;
import static org.opencoap.transport.mbedtls.DtlsTransportContext.DTLS_CID;
import static org.opencoap.transport.mbedtls.DtlsTransportContext.DTLS_PEER_CERTIFICATE_SUBJECT;
import com.mbed.coap.transport.TransportContext;
import java.util.Collections;
import org.junit.jupiter.api.Test;
import org.opencoap.ssl.transport.DtlsSessionContext;

public class DtlsTransportContextTest {

@Test
void shouldConvertEmptyDtlsSessionContext() {
TransportContext transCtx = DtlsTransportContext.toTransportContext(DtlsSessionContext.EMPTY);

assertTrue(transCtx.get(DTLS_AUTHENTICATION).isEmpty());
assertNull(transCtx.get(DTLS_PEER_CERTIFICATE_SUBJECT));
assertNull(transCtx.get(DTLS_CID));

assertEquals(transCtx, TransportContext.EMPTY);
}

@Test
void shouldConvertDtlsSessionContext() {
TransportContext transCtx = DtlsTransportContext.toTransportContext(
new DtlsSessionContext(Collections.singletonMap("a", "b"), "CN:aa", new byte[]{1, 2})
);

assertEquals("b", transCtx.get(DTLS_AUTHENTICATION).get("a"));
assertNull(transCtx.get(DTLS_AUTHENTICATION).get("fdsfs"));
assertEquals("CN:aa", transCtx.get(DTLS_PEER_CERTIFICATE_SUBJECT));
assertArrayEquals(new byte[]{1, 2}, transCtx.get(DTLS_CID));
}
}

0 comments on commit c4b9670

Please sign in to comment.