Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

Commit

Permalink
Add 'tryParse' method to KeyReaderHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
Cach30verfl0w committed Jun 14, 2024
1 parent eb68bad commit 62ddc8f
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,28 @@ object KeyReaderHelper {
return null
}

/**
* This method tries to parse the data in the specified pointer in a key. This method supports
* PEM and DER. If no supported format worked, this method simply returns null.
*
* @author Cedric Hammes
* @since 14/06/2024
*/
fun tryParse(pointer: CPointer<ByteVar>, size: ULong, purposes: UByte): Key? {
// Try to parse as PEM and return if successful
val pemKey = tryParseAsPEM(pointer, size, purposes)
if (pemKey != null) {
return pemKey
}

// Try to parse as DER and return if successful
val derKey = tryParseAsDER(pointer, size, purposes)
if (derKey != null) {
return derKey
}

// If no format works, return null
return null
}

}

0 comments on commit 62ddc8f

Please sign in to comment.