hasDerEs256Signature method
Whether credential contains a structurally complete DER sequence.
Implementation
bool hasDerEs256Signature(Map<String, dynamic> credential) {
final response = credential['response'];
if (response is! Map || response['signature'] is! String) return false;
try {
final bytes = _decodeBase64Url(response['signature'] as String);
if (bytes.length < 8 ||
bytes.first != 0x30 ||
bytes[1] != bytes.length - 2 ||
bytes[2] != 0x02) {
return false;
}
final rLength = bytes[3];
final sTag = 4 + rLength;
if (rLength < 1 ||
rLength > 33 ||
sTag + 2 > bytes.length ||
bytes[sTag] != 0x02) {
return false;
}
final sLength = bytes[sTag + 1];
return sLength >= 1 &&
sLength <= 33 &&
sTag + 2 + sLength == bytes.length;
} on FormatException {
return false;
}
}