16 lines
724 B
Dart
16 lines
724 B
Dart
/// Splits PEM material into its two parts. A Gemini identity commonly travels
|
|
/// as one .pem holding both the certificate and its private key, or as two
|
|
/// files; both cases come out of these two lookups.
|
|
library;
|
|
|
|
final _certificate = RegExp(
|
|
r'-----BEGIN CERTIFICATE-----[\s\S]*?-----END CERTIFICATE-----');
|
|
|
|
final _privateKey = RegExp(
|
|
r'-----BEGIN (?:RSA |EC )?PRIVATE KEY-----[\s\S]*?-----END (?:RSA |EC )?PRIVATE KEY-----');
|
|
|
|
/// The first certificate in [pem], or null when there is none.
|
|
String? certificateOf(String pem) => _certificate.firstMatch(pem)?.group(0);
|
|
|
|
/// The first private key in [pem], or null when there is none.
|
|
String? privateKeyOf(String pem) => _privateKey.firstMatch(pem)?.group(0);
|