@@ -257,6 +257,51 @@ private final class CustomKeyDelayedCompletion: NIOSSLCustomPrivateKey, Hashable
257257 }
258258}
259259
260+ private final class CustomKeyWithoutDERBytes : NIOSSLCustomPrivateKey , Hashable {
261+ var signatureAlgorithms : [ SignatureAlgorithm ] { [ ] }
262+
263+ func sign( channel: Channel , algorithm: SignatureAlgorithm , data: ByteBuffer ) -> EventLoopFuture < ByteBuffer > {
264+ fatalError ( " Not implemented " )
265+ }
266+
267+ func decrypt( channel: Channel , data: ByteBuffer ) -> EventLoopFuture < ByteBuffer > {
268+ fatalError ( " Not implemented " )
269+ }
270+
271+ static func == ( lhs: CustomKeyWithoutDERBytes , rhs: CustomKeyWithoutDERBytes ) -> Bool {
272+ lhs. signatureAlgorithms == rhs. signatureAlgorithms
273+ }
274+
275+ func hash( into hasher: inout Hasher ) {
276+ hasher. combine ( ObjectIdentifier ( self ) )
277+ hasher. combine ( signatureAlgorithms)
278+ }
279+ }
280+
281+ private final class CustomKeyWithDERBytes : NIOSSLCustomPrivateKey , Hashable {
282+ var signatureAlgorithms : [ NIOSSL . SignatureAlgorithm ] { [ ] }
283+
284+ var derBytes : [ UInt8 ] { [ 42 ] }
285+
286+ func sign( channel: Channel , algorithm: SignatureAlgorithm , data: ByteBuffer ) -> EventLoopFuture < ByteBuffer > {
287+ fatalError ( " Not implemented " )
288+ }
289+
290+ func decrypt( channel: Channel , data: ByteBuffer ) -> EventLoopFuture < ByteBuffer > {
291+ fatalError ( " Not implemented " )
292+ }
293+
294+ static func == ( lhs: CustomKeyWithDERBytes , rhs: CustomKeyWithDERBytes ) -> Bool {
295+ lhs. signatureAlgorithms == rhs. signatureAlgorithms && lhs. derBytes == rhs. derBytes
296+ }
297+
298+ func hash( into hasher: inout Hasher ) {
299+ hasher. combine ( ObjectIdentifier ( self ) )
300+ hasher. combine ( signatureAlgorithms)
301+ hasher. combine ( derBytes)
302+ }
303+ }
304+
260305final class CustomPrivateKeyTests : XCTestCase {
261306 fileprivate static let customECDSACertAndKey : ( certificate: NIOSSLCertificate , key: CustomPKEY ) = {
262307 let ( cert, originalKey) = generateSelfSignedCert ( keygenFunction: {
@@ -686,6 +731,20 @@ final class CustomPrivateKeyTests: XCTestCase {
686731 ] )
687732 )
688733 }
734+
735+ func testDERBytes_DefaultImplementation_ReturnsEmptyArray( ) throws {
736+ let customKey = CustomKeyWithoutDERBytes ( )
737+ let key = NIOSSLPrivateKey ( customPrivateKey: customKey)
738+ let derBytes = try key. derBytes
739+ XCTAssertEqual ( derBytes, [ ] )
740+ }
741+
742+ func testDERBytes_ReturnsBytes( ) throws {
743+ let customKey = CustomKeyWithDERBytes ( )
744+ let key = NIOSSLPrivateKey ( customPrivateKey: customKey)
745+ let derBytes = try key. derBytes
746+ XCTAssertEqual ( derBytes, [ 42 ] )
747+ }
689748}
690749
691750extension SignatureAlgorithm {
0 commit comments