Commit 993c6f60 authored by Lorenzo Pichilli's avatar Lorenzo Pichilli

v3.4.0

parent f6a6b4a6
......@@ -21,7 +21,6 @@ class ASN1DERDecoder {
asn1obj.identifier = ASN1Identifier(nextValue);
if (asn1obj.identifier.isConstructed()) {
var contentData = loadSubContent(iterator: iterator);
if (contentData.isEmpty) {
......@@ -39,9 +38,7 @@ class ASN1DERDecoder {
item.parent = asn1obj;
}
} else {
if (asn1obj.identifier.typeClass() == ASN1IdentifierClass.UNIVERSAL) {
var contentData = loadSubContent(iterator: iterator);
asn1obj.encoded = Uint8List.fromList(contentData);
......@@ -52,75 +49,62 @@ class ASN1DERDecoder {
if (tagNumber == ASN1IdentifierTagNumber.END_OF_CONTENT) {
return result;
}
else if (tagNumber == ASN1IdentifierTagNumber.BOOLEAN) {
} else if (tagNumber == ASN1IdentifierTagNumber.BOOLEAN) {
var value = contentData.length > 0 ? contentData.first : null;
if (value != null) {
asn1obj.value = value > 0 ? true : false;
}
}
else if (tagNumber == ASN1IdentifierTagNumber.INTEGER) {
} else if (tagNumber == ASN1IdentifierTagNumber.INTEGER) {
while (contentData.length > 0 && contentData.first == 0) {
contentData.removeAt(0); // remove not significant digit
}
asn1obj.value = contentData;
}
else if (tagNumber == ASN1IdentifierTagNumber.NULL) {
} else if (tagNumber == ASN1IdentifierTagNumber.NULL) {
asn1obj.value = null;
}
else if (tagNumber == ASN1IdentifierTagNumber.OBJECT_IDENTIFIER) {
} else if (tagNumber == ASN1IdentifierTagNumber.OBJECT_IDENTIFIER) {
asn1obj.value = decodeOid(contentData: contentData);
}
else if ([
} else if ([
ASN1IdentifierTagNumber.UTF8_STRING,
ASN1IdentifierTagNumber.PRINTABLE_STRING,
ASN1IdentifierTagNumber.NUMERIC_STRING,
ASN1IdentifierTagNumber.GENERAL_STRING,
ASN1IdentifierTagNumber.UNIVERSAL_STRING,
ASN1IdentifierTagNumber.CHARACTER_STRING,
ASN1IdentifierTagNumber.T61_STRING].contains(tagNumber)) {
ASN1IdentifierTagNumber.T61_STRING
].contains(tagNumber)) {
asn1obj.value = utf8.decode(contentData, allowMalformed: true);
}
else if (tagNumber == ASN1IdentifierTagNumber.BMP_STRING) {
} else if (tagNumber == ASN1IdentifierTagNumber.BMP_STRING) {
asn1obj.value = String.fromCharCodes(contentData);
}
else if ([
} else if ([
ASN1IdentifierTagNumber.VISIBLE_STRING,
ASN1IdentifierTagNumber.IA5_STRING
].contains(tagNumber)) {
asn1obj.value = ascii.decode(contentData, allowInvalid: true);
}
else if (tagNumber == ASN1IdentifierTagNumber.UTC_TIME) {
} else if (tagNumber == ASN1IdentifierTagNumber.UTC_TIME) {
asn1obj.value = utcTimeToDate(contentData: contentData);
}
else if (tagNumber == ASN1IdentifierTagNumber.GENERALIZED_TIME) {
} else if (tagNumber == ASN1IdentifierTagNumber.GENERALIZED_TIME) {
asn1obj.value = generalizedTimeToDate(contentData: contentData);
}
else if (tagNumber == ASN1IdentifierTagNumber.BIT_STRING) {
} else if (tagNumber == ASN1IdentifierTagNumber.BIT_STRING) {
if (contentData.length > 0) {
contentData.removeAt(0); // unused bits
}
asn1obj.value = contentData;
}
else if (tagNumber == ASN1IdentifierTagNumber.OCTET_STRING) {
} else if (tagNumber == ASN1IdentifierTagNumber.OCTET_STRING) {
try {
var subIterator = contentData.iterator;
asn1obj.sub = parse(iterator: subIterator);
} catch (e) {
var str;
try {
str = utf8.decode(contentData);
} catch(e) {}
} catch (e) {}
if (str != null) {
asn1obj.value = str;
} else {
asn1obj.value = contentData;
}
}
}
else {
} else {
// print("unsupported tag: ${asn1obj.identifier.tagNumber()}");
asn1obj.value = contentData;
}
......@@ -132,7 +116,7 @@ class ASN1DERDecoder {
var str;
try {
str = utf8.decode(contentData);
} catch(e) {}
} catch (e) {}
if (str != null) {
asn1obj.value = str;
} else {
......@@ -150,8 +134,8 @@ class ASN1DERDecoder {
if (iterator.moveNext()) {
var first = iterator.current;
if (first != null) {
if ((first & 0x80) != 0) { // long
if ((first & 0x80) != 0) {
// long
var octetsToRead = first - 0x80;
var data = <int>[];
......@@ -165,11 +149,10 @@ class ASN1DERDecoder {
}
return toIntValue(data) ?? BigInt.from(0);
} else { // short
} else {
// short
return BigInt.from(first);
}
}
}
return BigInt.from(0);
......@@ -251,7 +234,7 @@ class ASN1DERDecoder {
String utc;
try {
utc = utf8.decode(contentData);
} catch(e) {}
} catch (e) {}
if (utc == null) {
return null;
}
......@@ -268,36 +251,30 @@ class ASN1DERDecoder {
int end;
String c;
// not just YYMMDDhhmmZ
if(utc.length > 11) {
if (utc.length > 11) {
// get character after minutes
c = utc[10];
end = 10;
// see if seconds are present
if(c != '+' && c != '-') {
if (c != '+' && c != '-') {
// get seconds
ss = int.parse(utc.substring(10, 12), radix: 10);
end += 2;
}
}
var date = DateTime.utc(
year,
MM,
DD,
hh,
mm,
ss,
0
);
var date = DateTime.utc(year, MM, DD, hh, mm, ss, 0);
if(end != null) {
if (end != null) {
// get +/- after end of time
c = utc[end];
if(c == '+' || c == '-') {
if (c == '+' || c == '-') {
// get hours+minutes offset
var hhoffset = int.parse(utc.substring(end + 1, end + 1 + 2), radix: 10);
var mmoffset = int.parse(utc.substring(end + 4, end + 4 + 2), radix: 10);
var hhoffset =
int.parse(utc.substring(end + 1, end + 1 + 2), radix: 10);
var mmoffset =
int.parse(utc.substring(end + 4, end + 4 + 2), radix: 10);
// calculate offset in milliseconds
var offset = hhoffset * 60 + mmoffset;
......@@ -305,7 +282,7 @@ class ASN1DERDecoder {
var offsetDuration = Duration(milliseconds: offset);
// apply offset
if(c == '+') {
if (c == '+') {
date.subtract(offsetDuration);
} else {
date.add(offsetDuration);
......@@ -345,7 +322,7 @@ class ASN1DERDecoder {
String gentime;
try {
gentime = utf8.decode(contentData);
} catch(e) {}
} catch (e) {}
if (gentime == null) {
return null;
}
......@@ -362,23 +339,25 @@ class ASN1DERDecoder {
var offset = 0;
var isUTC = false;
if(gentime[gentime.length - 1] == 'Z') {
if (gentime[gentime.length - 1] == 'Z') {
isUTC = true;
}
var end = gentime.length - 5;
var c = gentime[end];
if(c == '+' || c == '-') {
if (c == '+' || c == '-') {
// get hours+minutes offset
var hhoffset = int.parse(gentime.substring(end + 1, end + 1 + 2), radix: 10);
var mmoffset = int.parse(gentime.substring(end + 4, end + 4 + 2), radix: 10);
var hhoffset =
int.parse(gentime.substring(end + 1, end + 1 + 2), radix: 10);
var mmoffset =
int.parse(gentime.substring(end + 4, end + 4 + 2), radix: 10);
// calculate offset in milliseconds
offset = hhoffset * 60 + mmoffset;
offset *= 60000;
// apply offset
if(c == '+') {
if (c == '+') {
offset *= -1;
}
......@@ -386,26 +365,17 @@ class ASN1DERDecoder {
}
// check for second fraction
if(gentime[14] == '.') {
if (gentime[14] == '.') {
fff = double.parse(gentime.substring(14)) * 1000;
}
var date = DateTime.utc(
YYYY,
MM,
DD,
hh,
mm,
ss,
fff.toInt()
);
var date = DateTime.utc(YYYY, MM, DD, hh, mm, ss, fff.toInt());
if(isUTC) {
if (isUTC) {
var offsetDuration = Duration(milliseconds: offset);
date.add(offsetDuration);
}
return date;
}
}
......@@ -418,15 +388,11 @@ BigInt toIntValue(List<int> data) {
BigInt value = BigInt.from(0);
for (var index = 0; index < data.length; index++) {
var byte = data[index];
value += BigInt.from(byte << 8*(data.length-index-1));
value += BigInt.from(byte << 8 * (data.length - index - 1));
}
return value;
}
class ASN1OutOfBufferError extends Error {
class ASN1OutOfBufferError extends Error {}
}
class ASN1ParseError extends Error {
}
\ No newline at end of file
class ASN1ParseError extends Error {}
......@@ -21,7 +21,8 @@ class ASN1DistinguishedNames {
static ASN1DistinguishedNames fromValue(String oid) {
if (oid != null)
return ASN1DistinguishedNames.values.firstWhere((element) => element.oid() == oid, orElse: () => null);
return ASN1DistinguishedNames.values
.firstWhere((element) => element.oid() == oid, orElse: () => null);
return null;
}
......@@ -32,18 +33,30 @@ class ASN1DistinguishedNames {
@override
String toString() => "($_oid, $_representation)";
static const COMMON_NAME = const ASN1DistinguishedNames._internal("2.5.4.3", "CN");
static const DN_QUALIFIER = const ASN1DistinguishedNames._internal("2.5.4.46", "DNQ");
static const SERIAL_NUMBER = const ASN1DistinguishedNames._internal("2.5.4.5", "SERIALNUMBER");
static const GIVEN_NAME = const ASN1DistinguishedNames._internal("2.5.4.42", "GIVENNAME");
static const SURNAME = const ASN1DistinguishedNames._internal("2.5.4.4", "SURNAME");
static const ORGANIZATIONAL_UNIT_NAME = const ASN1DistinguishedNames._internal("2.5.4.11", "OU");
static const ORGANIZATION_NAME = const ASN1DistinguishedNames._internal("2.5.4.10", "O");
static const STREET_ADDRESS = const ASN1DistinguishedNames._internal("2.5.4.9", "STREET");
static const LOCALITY_NAME = const ASN1DistinguishedNames._internal("2.5.4.7", "L");
static const STATE_OR_PROVINCE_NAME = const ASN1DistinguishedNames._internal("2.5.4.8", "ST");
static const COUNTRY_NAME = const ASN1DistinguishedNames._internal("2.5.4.6", "C");
static const EMAIL = const ASN1DistinguishedNames._internal("1.2.840.113549.1.9.1", "E");
static const COMMON_NAME =
const ASN1DistinguishedNames._internal("2.5.4.3", "CN");
static const DN_QUALIFIER =
const ASN1DistinguishedNames._internal("2.5.4.46", "DNQ");
static const SERIAL_NUMBER =
const ASN1DistinguishedNames._internal("2.5.4.5", "SERIALNUMBER");
static const GIVEN_NAME =
const ASN1DistinguishedNames._internal("2.5.4.42", "GIVENNAME");
static const SURNAME =
const ASN1DistinguishedNames._internal("2.5.4.4", "SURNAME");
static const ORGANIZATIONAL_UNIT_NAME =
const ASN1DistinguishedNames._internal("2.5.4.11", "OU");
static const ORGANIZATION_NAME =
const ASN1DistinguishedNames._internal("2.5.4.10", "O");
static const STREET_ADDRESS =
const ASN1DistinguishedNames._internal("2.5.4.9", "STREET");
static const LOCALITY_NAME =
const ASN1DistinguishedNames._internal("2.5.4.7", "L");
static const STATE_OR_PROVINCE_NAME =
const ASN1DistinguishedNames._internal("2.5.4.8", "ST");
static const COUNTRY_NAME =
const ASN1DistinguishedNames._internal("2.5.4.6", "C");
static const EMAIL =
const ASN1DistinguishedNames._internal("1.2.840.113549.1.9.1", "E");
bool operator ==(value) => value == _oid;
......
......@@ -12,7 +12,9 @@ class ASN1IdentifierClass {
static ASN1IdentifierClass fromValue(int value) {
if (value != null)
return ASN1IdentifierClass.values.firstWhere((element) => element.toValue() == value, orElse: () => null);
return ASN1IdentifierClass.values.firstWhere(
(element) => element.toValue() == value,
orElse: () => null);
return null;
}
......@@ -81,7 +83,9 @@ class ASN1IdentifierTagNumber {
static ASN1IdentifierTagNumber fromValue(int value) {
if (value != null)
return ASN1IdentifierTagNumber.values.firstWhere((element) => element.toValue() == value, orElse: () => null);
return ASN1IdentifierTagNumber.values.firstWhere(
(element) => element.toValue() == value,
orElse: () => null);
return null;
}
......@@ -93,8 +97,10 @@ class ASN1IdentifierTagNumber {
static const BIT_STRING = const ASN1IdentifierTagNumber._internal(0x03);
static const OCTET_STRING = const ASN1IdentifierTagNumber._internal(0x04);
static const NULL = const ASN1IdentifierTagNumber._internal(0x05);
static const OBJECT_IDENTIFIER = const ASN1IdentifierTagNumber._internal(0x06);
static const OBJECT_DESCRIPTOR = const ASN1IdentifierTagNumber._internal(0x07);
static const OBJECT_IDENTIFIER =
const ASN1IdentifierTagNumber._internal(0x06);
static const OBJECT_DESCRIPTOR =
const ASN1IdentifierTagNumber._internal(0x07);
static const EXTERNAL = const ASN1IdentifierTagNumber._internal(0x08);
static const READ = const ASN1IdentifierTagNumber._internal(0x09);
static const ENUMERATED = const ASN1IdentifierTagNumber._internal(0x0A);
......@@ -200,11 +206,16 @@ class ASN1Identifier {
}
ASN1IdentifierTagNumber tagNumber() {
return ASN1IdentifierTagNumber.fromValue(rawValue & 0x1F) ?? ASN1IdentifierTagNumber.END_OF_CONTENT;
return ASN1IdentifierTagNumber.fromValue(rawValue & 0x1F) ??
ASN1IdentifierTagNumber.END_OF_CONTENT;
}
ASN1IdentifierClass typeClass() {
for (var tc in [ASN1IdentifierClass.APPLICATION, ASN1IdentifierClass.CONTEXT_SPECIFIC, ASN1IdentifierClass.PRIVATE]) {
for (var tc in [
ASN1IdentifierClass.APPLICATION,
ASN1IdentifierClass.CONTEXT_SPECIFIC,
ASN1IdentifierClass.PRIVATE
]) {
if ((rawValue & tc.toValue()) == tc.toValue()) {
return tc;
}
......
......@@ -46,12 +46,12 @@ class ASN1Object {
ASN1Object findOid({OID oid, String oidValue}) {
oidValue = oid != null ? oid.toValue() : oidValue;
for (var child in (sub ?? <ASN1Object>[])) {
if (child.identifier?.tagNumber() == ASN1IdentifierTagNumber.OBJECT_IDENTIFIER) {
if (child.identifier?.tagNumber() ==
ASN1IdentifierTagNumber.OBJECT_IDENTIFIER) {
if (child.value == oidValue) {
return child;
}
}
else {
} else {
var result = child.findOid(oidValue: oidValue);
if (result != null) {
return result;
......@@ -69,7 +69,8 @@ class ASN1Object {
var output = insets;
output += identifier?.description?.toUpperCase() ?? "";
output += (value != null ? ": $value" : "");
if (identifier?.typeClass() == ASN1IdentifierClass.UNIVERSAL && identifier?.tagNumber() == ASN1IdentifierTagNumber.OBJECT_IDENTIFIER) {
if (identifier?.typeClass() == ASN1IdentifierClass.UNIVERSAL &&
identifier?.tagNumber() == ASN1IdentifierTagNumber.OBJECT_IDENTIFIER) {
var descr = OID.fromValue(value?.toString() ?? "")?.name();
if (descr != null) {
output += " ($descr)";
......
......@@ -16,7 +16,8 @@ class KeyUsage {
].toSet();
static KeyUsage fromIndex(int value) {
return KeyUsage.values.firstWhere((element) => element.toValue() == value, orElse: () => null);
return KeyUsage.values.firstWhere((element) => element.toValue() == value,
orElse: () => null);
}
int toValue() => _value;
......
......@@ -103,7 +103,8 @@ class OID {
].toSet();
static OID fromValue(String value) {
return OID.values.firstWhere((element) => element.toValue() == value, orElse: () => null);
return OID.values.firstWhere((element) => element.toValue() == value,
orElse: () => null);
}
String toValue() => _value;
......@@ -122,29 +123,40 @@ class OID {
static const ecdsaWithSHA256 = const OID._internal("1.2.840.10045.4.3.2");
static const ecdsaWithSHA512 = const OID._internal("1.2.840.10045.4.3.4");
static const rsaEncryption = const OID._internal("1.2.840.113549.1.1.1");
static const md2WithRSAEncryption = const OID._internal("1.2.840.113549.1.1.2");
static const md4WithRSAEncryption = const OID._internal("1.2.840.113549.1.1.3");
static const md5WithRSAEncryption = const OID._internal("1.2.840.113549.1.1.4");
static const sha1WithRSAEncryption = const OID._internal("1.2.840.113549.1.1.5");
static const md2WithRSAEncryption =
const OID._internal("1.2.840.113549.1.1.2");
static const md4WithRSAEncryption =
const OID._internal("1.2.840.113549.1.1.3");
static const md5WithRSAEncryption =
const OID._internal("1.2.840.113549.1.1.4");
static const sha1WithRSAEncryption =
const OID._internal("1.2.840.113549.1.1.5");
static const RSAES_OAEP = const OID._internal("1.2.840.113549.1.1.7");
static const mgf1 = const OID._internal(".2.840.113549.1.1.8");
static const pSpecified = const OID._internal(".2.840.113549.1.1.9");
static const RSASSA_PSS = const OID._internal(".2.840.113549.1.1.10");
static const sha256WithRSAEncryption = const OID._internal("1.2.840.113549.1.1.11");
static const sha384WithRSAEncryption = const OID._internal("1.2.840.113549.1.1.12");
static const sha512WithRSAEncryption = const OID._internal("1.2.840.113549.1.1.13");
static const sha256WithRSAEncryption =
const OID._internal("1.2.840.113549.1.1.11");
static const sha384WithRSAEncryption =
const OID._internal("1.2.840.113549.1.1.12");
static const sha512WithRSAEncryption =
const OID._internal("1.2.840.113549.1.1.13");
static const pkcs7data = const OID._internal("1.2.840.113549.1.7.1");
static const pkcs7signedData = const OID._internal("1.2.840.113549.1.7.2");
static const pkcs7envelopedData = const OID._internal("1.2.840.113549.1.7.3");
static const emailAddress = const OID._internal("1.2.840.113549.1.9.1");
static const signingCertificateV2 = const OID._internal("1.2.840.113549.1.9.16.2.47");
static const signingCertificateV2 =
const OID._internal("1.2.840.113549.1.9.16.2.47");
static const contentType = const OID._internal("1.2.840.113549.1.9.3");
static const messageDigest = const OID._internal("1.2.840.113549.1.9.4");
static const signingTime = const OID._internal("1.2.840.113549.1.9.5");
static const dsaWithSha1 = const OID._internal("1.2.840.10040.4.3");
static const certificateExtension = const OID._internal("1.3.6.1.4.1.11129.2.4.2");
static const jurisdictionOfIncorporationSP = const OID._internal("1.3.6.1.4.1.311.60.2.1.2");
static const jurisdictionOfIncorporationC = const OID._internal("1.3.6.1.4.1.311.60.2.1.3");
static const certificateExtension =
const OID._internal("1.3.6.1.4.1.11129.2.4.2");
static const jurisdictionOfIncorporationSP =
const OID._internal("1.3.6.1.4.1.311.60.2.1.2");
static const jurisdictionOfIncorporationC =
const OID._internal("1.3.6.1.4.1.311.60.2.1.3");
static const authorityInfoAccess = const OID._internal("1.3.6.1.5.5.7.1.1");
static const qcStatements = const OID._internal("1.3.6.1.5.5.7.1.3");
static const cps = const OID._internal("1.3.6.1.5.5.7.2.1");
......@@ -160,7 +172,8 @@ class OID {
static const sha384 = const OID._internal("2.16.840.1.101.3.4.2.2");
static const sha512 = const OID._internal("2.16.840.1.101.3.4.2.3");
static const md5 = const OID._internal("1.2.840.113549.2.5");
static const VeriSignEVpolicy = const OID._internal("2.16.840.1.113733.1.7.23.6");
static const VeriSignEVpolicy =
const OID._internal("2.16.840.1.113733.1.7.23.6");
static const extendedValidation = const OID._internal("2.23.140.1.1");
static const organizationValidated = const OID._internal("2.23.140.1.2.2");
static const subjectKeyIdentifier = const OID._internal("2.5.29.14");
......
......@@ -322,7 +322,11 @@ class X509Certificate {
///Gets the certificate constraints path length from the
///critical BasicConstraints extension, (OID = 2.5.29.19).
int get basicConstraints {
var sub = extensionObject(oid: OID.basicConstraints)?.block?.lastSub()?.lastSub()?.lastSub();
var sub = extensionObject(oid: OID.basicConstraints)
?.block
?.lastSub()
?.lastSub()
?.lastSub();
if (sub != null) {
if (sub.value is List<int>) {
return (sub.value as List<int>).length;
......@@ -333,31 +337,60 @@ class X509Certificate {
///Gets the raw bits from the Subject Key Identifier (SKID) extension, (OID = 2.5.29.14).
List<int> get subjectKeyIdentifier =>
extensionObject(oid: OID.subjectKeyIdentifier)?.block?.lastSub()?.lastSub()?.value ?? <int>[];
extensionObject(oid: OID.subjectKeyIdentifier)
?.block
?.lastSub()
?.lastSub()
?.value ??
<int>[];
///Gets the raw bits from the Authority Key Identifier extension, (OID = 2.5.29.35).
List<int> get authorityKeyIdentifier =>
extensionObject(oid: OID.authorityKeyIdentifier)?.block?.lastSub()?.lastSub()?.firstSub()?.value ?? <int>[];
extensionObject(oid: OID.authorityKeyIdentifier)
?.block
?.lastSub()
?.lastSub()
?.firstSub()
?.value ??
<int>[];
///Gets the list of certificate policies from the CertificatePolicies extension, (OID = 2.5.29.32).
List<String> get certificatePolicies =>
extensionObject(oid: OID.certificatePolicies)?.block?.lastSub()?.firstSub()?.sub?.map((e) => e.firstSub()?.value as String)?.toList() ?? <String>[];
extensionObject(oid: OID.certificatePolicies)
?.block
?.lastSub()
?.firstSub()
?.sub
?.map((e) => e.firstSub()?.value as String)
?.toList() ??
<String>[];
///Gets the list of CRL distribution points from the CRLDistributionPoints extension, (OID = 2.5.29.31).
List<String> get cRLDistributionPoints =>
extensionObject(oid: OID.cRLDistributionPoints)?.block?.lastSub()?.firstSub()?.sub?.map((e) => e.firstSub()?.firstSub()?.firstSub()?.value as String)?.toList() ?? <String>[];
extensionObject(oid: OID.cRLDistributionPoints)
?.block
?.lastSub()
?.firstSub()
?.sub
?.map((e) => e.firstSub()?.firstSub()?.firstSub()?.value as String)
?.toList() ??
<String>[];
///Gets the map of the format (as a key) and location (as a value) of additional information
///about the CA who issued the certificate in which this extension appears
///from the AuthorityInfoAccess extension, (OID = 1.3.6.1.5.5.5.7.1.1).
Map<String, String> get authorityInfoAccess {
var result = <String, String>{};
var sub = extensionObject(oid: OID.authorityInfoAccess)?.block?.lastSub()?.firstSub()?.sub;
var sub = extensionObject(oid: OID.authorityInfoAccess)
?.block
?.lastSub()
?.firstSub()
?.sub;
if (sub != null) {
sub.forEach((element) {
if (element.subCount() > 1) {
result.putIfAbsent(element.subAtIndex(0).value,
() => element.subAtIndex(1).value);
result.putIfAbsent(
element.subAtIndex(0).value, () => element.subAtIndex(1).value);
}
});
}
......@@ -413,8 +446,6 @@ class X509Certificate {
result += quote;
}
}
}
}
return result;
......
......@@ -25,11 +25,13 @@ class X509PublicKey {
} else if (oid == OID.rsaEncryption) {
List<ASN1Object> publicKeyAsn1Objects;
try {
publicKeyAsn1Objects = ASN1DERDecoder.decode(data: keyData.toList(growable: true));
} catch(e) {}
publicKeyAsn1Objects =
ASN1DERDecoder.decode(data: keyData.toList(growable: true));
} catch (e) {}
if (publicKeyAsn1Objects != null && publicKeyAsn1Objects.length > 0) {
var publicKeyModulus = publicKeyAsn1Objects.first?.subAtIndex(0)?.value;
var publicKeyModulus =
publicKeyAsn1Objects.first?.subAtIndex(0)?.value;
if (publicKeyModulus != null) {
return Uint8List.fromList(publicKeyModulus);
}
......
......@@ -84,7 +84,8 @@ class CookieManager {
expiresDate: cookieListMap[i]["expiresDate"],
isSessionOnly: cookieListMap[i]["isSessionOnly"],
domain: cookieListMap[i]["domain"],
sameSite: HTTPCookieSameSitePolicy.fromValue(cookieListMap[i]["sameSite"]),
sameSite:
HTTPCookieSameSitePolicy.fromValue(cookieListMap[i]["sameSite"]),
isSecure: cookieListMap[i]["isSecure"],
isHttpOnly: cookieListMap[i]["isHttpOnly"],
path: cookieListMap[i]["path"]));
......@@ -111,7 +112,8 @@ class CookieManager {
expiresDate: cookies[i]["expiresDate"],
isSessionOnly: cookies[i]["isSessionOnly"],
domain: cookies[i]["domain"],
sameSite: HTTPCookieSameSitePolicy.fromValue(cookies[i]["sameSite"]),
sameSite:
HTTPCookieSameSitePolicy.fromValue(cookies[i]["sameSite"]),
isSecure: cookies[i]["isSecure"],
isHttpOnly: cookies[i]["isHttpOnly"],
path: cookies[i]["path"]);
......
......@@ -31,7 +31,8 @@ class HttpAuthCredentialDatabase {
///Gets a map list of all HTTP auth credentials saved.
///Each map contains the key `protectionSpace` of type [ProtectionSpace]
///and the key `credentials` of type `List<HttpAuthCredential>` that contains all the HTTP auth credentials saved for that `protectionSpace`.
Future<List<ProtectionSpaceHttpAuthCredentials>> getAllAuthCredentials() async {
Future<List<ProtectionSpaceHttpAuthCredentials>>
getAllAuthCredentials() async {
Map<String, dynamic> args = <String, dynamic>{};
List<dynamic> allCredentials =
await _channel.invokeMethod('getAllAuthCredentials', args);
......@@ -41,8 +42,7 @@ class HttpAuthCredentialDatabase {
for (Map<dynamic, dynamic> map in allCredentials) {
Map<dynamic, dynamic> protectionSpace = map["protectionSpace"];
List<dynamic> credentials = map["credentials"];
result.add(
ProtectionSpaceHttpAuthCredentials(
result.add(ProtectionSpaceHttpAuthCredentials(
protectionSpace: ProtectionSpace(
host: protectionSpace["host"],
protocol: protectionSpace["protocol"],
......@@ -52,9 +52,7 @@ class HttpAuthCredentialDatabase {
.map((credential) => HttpAuthCredential(
username: credential["username"],
password: credential["password"]))
.toList()
)
);
.toList()));
}
return result;
}
......
......@@ -69,7 +69,8 @@ class InAppWebViewController {
this._webview = webview;
this.android = AndroidInAppWebViewController(this);
this.ios = IOSInAppWebViewController(this);
this.webStorage = WebStorage(localStorage: LocalStorage(this), sessionStorage: SessionStorage(this));
this.webStorage = WebStorage(
localStorage: LocalStorage(this), sessionStorage: SessionStorage(this));
}
InAppWebViewController.fromInAppBrowser(
......@@ -369,29 +370,45 @@ class InAppWebViewController {
int androidError = call.arguments["androidError"];
int iosError = call.arguments["iosError"];
String message = call.arguments["message"];
Map<String, dynamic> sslCertificateMap = call.arguments["sslCertificate"]?.cast<String, dynamic>();
Map<String, dynamic> sslCertificateMap =
call.arguments["sslCertificate"]?.cast<String, dynamic>();
SslCertificate sslCertificate;
if (sslCertificateMap != null) {
if (Platform.isIOS) {
try {
X509Certificate x509certificate = X509Certificate.fromData(data: sslCertificateMap["x509Certificate"]);
X509Certificate x509certificate = X509Certificate.fromData(
data: sslCertificateMap["x509Certificate"]);
sslCertificate = SslCertificate(
issuedBy: SslCertificateDName(
CName: x509certificate.issuer(dn: ASN1DistinguishedNames.COMMON_NAME) ?? "",
CName: x509certificate.issuer(
dn: ASN1DistinguishedNames.COMMON_NAME) ??
"",
DName: x509certificate.issuerDistinguishedName ?? "",
OName: x509certificate.issuer(dn: ASN1DistinguishedNames.ORGANIZATION_NAME) ?? "",
UName: x509certificate.issuer(dn: ASN1DistinguishedNames.ORGANIZATIONAL_UNIT_NAME) ?? ""),
OName: x509certificate.issuer(
dn: ASN1DistinguishedNames.ORGANIZATION_NAME) ??
"",
UName: x509certificate.issuer(
dn: ASN1DistinguishedNames
.ORGANIZATIONAL_UNIT_NAME) ??
""),
issuedTo: SslCertificateDName(
CName: x509certificate.subject(dn: ASN1DistinguishedNames.COMMON_NAME) ?? "",
CName: x509certificate.subject(
dn: ASN1DistinguishedNames.COMMON_NAME) ??
"",
DName: x509certificate.subjectDistinguishedName ?? "",
OName: x509certificate.subject(dn: ASN1DistinguishedNames.ORGANIZATION_NAME) ?? "",
UName: x509certificate.subject(dn: ASN1DistinguishedNames.ORGANIZATIONAL_UNIT_NAME) ?? ""),
OName: x509certificate.subject(
dn: ASN1DistinguishedNames.ORGANIZATION_NAME) ??
"",
UName: x509certificate.subject(
dn: ASN1DistinguishedNames
.ORGANIZATIONAL_UNIT_NAME) ??
""),
validNotAfterDate: x509certificate.notAfter,
validNotBeforeDate: x509certificate.notBefore,
x509Certificate: x509certificate,
);
} catch(e, stacktrace) {
} catch (e, stacktrace) {
print(e);
print(stacktrace);
return null;
......@@ -401,8 +418,11 @@ class InAppWebViewController {
}
}
AndroidSslError androidSslError = androidError != null ? AndroidSslError.fromValue(androidError) : null;
IOSSslError iosSslError = iosError != null ? IOSSslError.fromValue(iosError) : null;
AndroidSslError androidSslError = androidError != null
? AndroidSslError.fromValue(androidError)
: null;
IOSSslError iosSslError =
iosError != null ? IOSSslError.fromValue(iosError) : null;
var protectionSpace = ProtectionSpace(
host: host, protocol: protocol, realm: realm, port: port);
......@@ -884,8 +904,7 @@ class InAppWebViewController {
InAppWebViewGroupOptions options = await getOptions();
if (options != null && options.crossPlatform.javaScriptEnabled == true) {
List<Map<dynamic, dynamic>> links = (await evaluateJavascript(
source: """
List<Map<dynamic, dynamic>> links = (await evaluateJavascript(source: """
(function() {
var linkNodes = document.head.getElementsByTagName("link");
var links = [];
......@@ -1466,7 +1485,8 @@ class InAppWebViewController {
///
///**Official Android API**: https://developer.android.com/reference/android/view/View#scrollTo(int,%20int)
///**Official iOS API**: https://developer.apple.com/documentation/uikit/uiscrollview/1619400-setcontentoffset
Future<void> scrollTo({@required int x, @required int y, bool animated = false}) async {
Future<void> scrollTo(
{@required int x, @required int y, bool animated = false}) async {
assert(x != null && y != null);
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('x', () => x);
......@@ -1485,7 +1505,8 @@ class InAppWebViewController {
///
///**Official Android API**: https://developer.android.com/reference/android/view/View#scrollBy(int,%20int)
///**Official iOS API**: https://developer.apple.com/documentation/uikit/uiscrollview/1619400-setcontentoffset
Future<void> scrollBy({@required int x, @required int y, bool animated = false}) async {
Future<void> scrollBy(
{@required int x, @required int y, bool animated = false}) async {
assert(x != null && y != null);
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('x', () => x);
......@@ -1544,7 +1565,8 @@ class InAppWebViewController {
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#zoomBy(float)
///**Official iOS API**: https://developer.apple.com/documentation/uikit/uiscrollview/1619412-setzoomscale
Future<void> zoomBy(double zoomFactor) async {
assert(!Platform.isAndroid || (Platform.isAndroid && zoomFactor > 0.01 && zoomFactor <= 100.0));
assert(!Platform.isAndroid ||
(Platform.isAndroid && zoomFactor > 0.01 && zoomFactor <= 100.0));
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('zoomFactor', () => zoomFactor);
......@@ -1611,12 +1633,15 @@ class InAppWebViewController {
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#requestFocusNodeHref(android.os.Message)
Future<RequestFocusNodeHrefResult> requestFocusNodeHref() async {
Map<String, dynamic> args = <String, dynamic>{};
Map<dynamic, dynamic> result = await _channel.invokeMethod('requestFocusNodeHref', args);
return result != null ? RequestFocusNodeHrefResult(
Map<dynamic, dynamic> result =
await _channel.invokeMethod('requestFocusNodeHref', args);
return result != null
? RequestFocusNodeHrefResult(
url: result['url'],
title: result['title'],
src: result['src'],
) : null;
)
: null;
}
///Requests the URL of the image last touched by the user.
......@@ -1626,10 +1651,13 @@ class InAppWebViewController {
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#requestImageRef(android.os.Message)
Future<RequestImageRefResult> requestImageRef() async {
Map<String, dynamic> args = <String, dynamic>{};
Map<dynamic, dynamic> result = await _channel.invokeMethod('requestImageRef', args);
return result != null ? RequestImageRefResult(
Map<dynamic, dynamic> result =
await _channel.invokeMethod('requestImageRef', args);
return result != null
? RequestImageRefResult(
url: result['url'],
) : null;
)
: null;
}
///Returns the list of `<meta>` tags of the current WebView.
......@@ -1638,7 +1666,8 @@ class InAppWebViewController {
Future<List<MetaTag>> getMetaTags() async {
List<MetaTag> metaTags = [];
List<Map<dynamic, dynamic>> metaTagList = (await evaluateJavascript(source: """
List<Map<dynamic, dynamic>> metaTagList =
(await evaluateJavascript(source: """
(function() {
var metaTags = [];
var metaTagNodes = document.head.getElementsByTagName('meta');
......@@ -1682,14 +1711,12 @@ class InAppWebViewController {
var attrs = <MetaTagAttribute>[];
for (var metaTagAttr in metaTag["attrs"]) {
attrs.add(
MetaTagAttribute(name: metaTagAttr["name"], value: metaTagAttr["value"])
);
attrs.add(MetaTagAttribute(
name: metaTagAttr["name"], value: metaTagAttr["value"]));
}
metaTags.add(
MetaTag(name: metaTag["name"], content: metaTag["content"], attrs: attrs)
);
metaTags.add(MetaTag(
name: metaTag["name"], content: metaTag["content"], attrs: attrs));
}
return metaTags;
......@@ -1743,28 +1770,43 @@ class InAppWebViewController {
Future<SslCertificate> getCertificate() async {
Map<String, dynamic> args = <String, dynamic>{};
Map<String, dynamic> sslCertificateMap = (await _channel.invokeMethod('getCertificate', args))?.cast<String, dynamic>();
Map<String, dynamic> sslCertificateMap =
(await _channel.invokeMethod('getCertificate', args))
?.cast<String, dynamic>();
if (sslCertificateMap != null) {
if (Platform.isIOS) {
try {
X509Certificate x509certificate = X509Certificate.fromData(data: sslCertificateMap["x509Certificate"]);
X509Certificate x509certificate = X509Certificate.fromData(
data: sslCertificateMap["x509Certificate"]);
return SslCertificate(
issuedBy: SslCertificateDName(
CName: x509certificate.issuer(dn: ASN1DistinguishedNames.COMMON_NAME) ?? "",
CName: x509certificate.issuer(
dn: ASN1DistinguishedNames.COMMON_NAME) ??
"",
DName: x509certificate.issuerDistinguishedName ?? "",
OName: x509certificate.issuer(dn: ASN1DistinguishedNames.ORGANIZATION_NAME) ?? "",
UName: x509certificate.issuer(dn: ASN1DistinguishedNames.ORGANIZATIONAL_UNIT_NAME) ?? ""),
OName: x509certificate.issuer(
dn: ASN1DistinguishedNames.ORGANIZATION_NAME) ??
"",
UName: x509certificate.issuer(
dn: ASN1DistinguishedNames.ORGANIZATIONAL_UNIT_NAME) ??
""),
issuedTo: SslCertificateDName(
CName: x509certificate.subject(dn: ASN1DistinguishedNames.COMMON_NAME) ?? "",
CName: x509certificate.subject(
dn: ASN1DistinguishedNames.COMMON_NAME) ??
"",
DName: x509certificate.subjectDistinguishedName ?? "",
OName: x509certificate.subject(dn: ASN1DistinguishedNames.ORGANIZATION_NAME) ?? "",
UName: x509certificate.subject(dn: ASN1DistinguishedNames.ORGANIZATIONAL_UNIT_NAME) ?? ""),
OName: x509certificate.subject(
dn: ASN1DistinguishedNames.ORGANIZATION_NAME) ??
"",
UName: x509certificate.subject(
dn: ASN1DistinguishedNames.ORGANIZATIONAL_UNIT_NAME) ??
""),
validNotAfterDate: x509certificate.notAfter,
validNotBeforeDate: x509certificate.notBefore,
x509Certificate: x509certificate,
);
} catch(e, stacktrace) {
} catch (e, stacktrace) {
print(e);
print(stacktrace);
return null;
......
......@@ -46,7 +46,9 @@ class ConsoleMessageLevel {
static ConsoleMessageLevel fromValue(int value) {
if (value != null)
return ConsoleMessageLevel.values.firstWhere((element) => element.toValue() == value, orElse: () => null);
return ConsoleMessageLevel.values.firstWhere(
(element) => element.toValue() == value,
orElse: () => null);
return null;
}
......@@ -134,7 +136,8 @@ class InAppWebViewInitialData {
///The URL to use as the history entry. The default value is `about:blank`. If non-null, this must be a valid URL. This parameter is used only on Android.
String historyUrl;
InAppWebViewInitialData({@required this.data,
InAppWebViewInitialData(
{@required this.data,
this.mimeType = "text/html",
this.encoding = "utf8",
this.baseUrl = "about:blank",
......@@ -196,7 +199,8 @@ class WebResourceRequest {
///**NOTE**: Available on Android 21+. For Android < 21 it will be always `false`.
bool isRedirect;
WebResourceRequest({@required this.url,
WebResourceRequest(
{@required this.url,
this.headers,
this.method,
this.hasGesture,
......@@ -255,7 +259,8 @@ class WebResourceResponse {
///**NOTE**: Available on Android 21+. For Android < 21 it won't be used.
String reasonPhrase;
WebResourceResponse({this.contentType = "",
WebResourceResponse(
{this.contentType = "",
this.contentEncoding = "utf-8",
this.data,
this.headers,
......@@ -294,7 +299,8 @@ class CustomSchemeResponse {
///Content-Enconding of the data, such as `utf-8`.
String contentEnconding;
CustomSchemeResponse({@required this.data,
CustomSchemeResponse(
{@required this.data,
@required this.contentType,
this.contentEnconding = 'utf-8'});
......@@ -463,7 +469,8 @@ class JsAlertResponse {
///Action used to confirm that the user hit confirm button.
JsAlertResponseAction action;
JsAlertResponse({this.message = "",
JsAlertResponse(
{this.message = "",
this.handledByClient = false,
this.confirmButtonTitle = "",
this.action = JsAlertResponseAction.CONFIRM});
......@@ -521,7 +528,8 @@ class JsConfirmResponse {
///Action used to confirm that the user hit confirm or cancel button.
JsConfirmResponseAction action;
JsConfirmResponse({this.message = "",
JsConfirmResponse(
{this.message = "",
this.handledByClient = false,
this.confirmButtonTitle = "",
this.cancelButtonTitle = "",
......@@ -587,7 +595,8 @@ class JsPromptResponse {
///Action used to confirm that the user hit confirm or cancel button.
JsPromptResponseAction action;
JsPromptResponse({this.message = "",
JsPromptResponse(
{this.message = "",
this.defaultValue = "",
this.handledByClient = false,
this.confirmButtonTitle = "",
......@@ -633,7 +642,9 @@ class SafeBrowsingThreat {
static SafeBrowsingThreat fromValue(int value) {
if (value != null)
return SafeBrowsingThreat.values.firstWhere((element) => element.toValue() == value, orElse: () => null);
return SafeBrowsingThreat.values.firstWhere(
(element) => element.toValue() == value,
orElse: () => null);
return null;
}
......@@ -705,7 +716,8 @@ class SafeBrowsingResponse {
///Indicate the [SafeBrowsingResponseAction] to take when hitting a malicious URL.
SafeBrowsingResponseAction action;
SafeBrowsingResponse({this.report = true,
SafeBrowsingResponse(
{this.report = true,
this.action = SafeBrowsingResponseAction.SHOW_INTERSTITIAL});
Map<String, dynamic> toMap() {
......@@ -760,7 +772,8 @@ class HttpAuthResponse {
///Indicate the [HttpAuthResponseAction] to take in response of the authentication challenge.
HttpAuthResponseAction action;
HttpAuthResponse({this.username = "",
HttpAuthResponse(
{this.username = "",
this.password = "",
this.permanentPersistence = false,
this.action = HttpAuthResponseAction.CANCEL});
......@@ -888,7 +901,8 @@ class ProtectionSpaceHttpAuthCredentials {
Map<String, dynamic> toMap() {
return {
"protectionSpace": protectionSpace?.toMap(),
"credentials": credentials?.map((credential) => credential?.toMap())?.toList()
"credentials":
credentials?.map((credential) => credential?.toMap())?.toList()
};
}
......@@ -963,7 +977,8 @@ class ServerTrustChallenge {
///The SSL certificate used for this challenge.
SslCertificate sslCertificate;
ServerTrustChallenge({@required this.protectionSpace,
ServerTrustChallenge(
{@required this.protectionSpace,
this.androidError,
this.iosError,
this.message,
......@@ -1027,7 +1042,8 @@ class ClientCertResponse {
///Indicate the [ClientCertResponseAction] to take in response of the client certificate challenge.
ClientCertResponseAction action;
ClientCertResponse({this.certificatePath,
ClientCertResponse(
{this.certificatePath,
this.certificatePassword = "",
this.androidKeyStoreType = "PKCS12",
this.action = ClientCertResponseAction.CANCEL}) {
......@@ -1123,7 +1139,9 @@ class AndroidCacheMode {
static AndroidCacheMode fromValue(int value) {
if (value != null)
return AndroidCacheMode.values.firstWhere((element) => element.toValue() == value, orElse: () => null);
return AndroidCacheMode.values.firstWhere(
(element) => element.toValue() == value,
orElse: () => null);
return null;
}
......@@ -1180,7 +1198,9 @@ class AndroidActionModeMenuItem {
static AndroidActionModeMenuItem fromValue(int value) {
if (value != null)
return AndroidActionModeMenuItem.values.firstWhere((element) => element.toValue() == value, orElse: () => null);
return AndroidActionModeMenuItem.values.firstWhere(
(element) => element.toValue() == value,
orElse: () => null);
return null;
}
......@@ -1237,7 +1257,9 @@ class AndroidForceDark {
static AndroidForceDark fromValue(int value) {
if (value != null)
return AndroidForceDark.values.firstWhere((element) => element.toValue() == value, orElse: () => null);
return AndroidForceDark.values.firstWhere(
(element) => element.toValue() == value,
orElse: () => null);
return null;
}
......@@ -1286,7 +1308,9 @@ class AndroidLayoutAlgorithm {
static AndroidLayoutAlgorithm fromValue(String value) {
if (value != null)
return AndroidLayoutAlgorithm.values.firstWhere((element) => element.toValue() == value, orElse: () => null);
return AndroidLayoutAlgorithm.values.firstWhere(
(element) => element.toValue() == value,
orElse: () => null);
return null;
}
......@@ -1331,7 +1355,9 @@ class AndroidMixedContentMode {
static AndroidMixedContentMode fromValue(int value) {
if (value != null)
return AndroidMixedContentMode.values.firstWhere((element) => element.toValue() == value, orElse: () => null);
return AndroidMixedContentMode.values.firstWhere(
(element) => element.toValue() == value,
orElse: () => null);
return null;
}
......@@ -1387,7 +1413,9 @@ class IOSWKSelectionGranularity {
static IOSWKSelectionGranularity fromValue(int value) {
if (value != null)
return IOSWKSelectionGranularity.values.firstWhere((element) => element.toValue() == value, orElse: () => null);
return IOSWKSelectionGranularity.values.firstWhere(
(element) => element.toValue() == value,
orElse: () => null);
return null;
}
......@@ -1439,7 +1467,9 @@ class IOSWKDataDetectorTypes {
static IOSWKDataDetectorTypes fromValue(String value) {
if (value != null)
return IOSWKDataDetectorTypes.values.firstWhere((element) => element.toValue() == value, orElse: () => null);
return IOSWKDataDetectorTypes.values.firstWhere(
(element) => element.toValue() == value,
orElse: () => null);
return null;
}
......@@ -1503,7 +1533,9 @@ class IOSUIScrollViewDecelerationRate {
static IOSUIScrollViewDecelerationRate fromValue(String value) {
if (value != null)
return IOSUIScrollViewDecelerationRate.values.firstWhere((element) => element.toValue() == value, orElse: () => null);
return IOSUIScrollViewDecelerationRate.values.firstWhere(
(element) => element.toValue() == value,
orElse: () => null);
return null;
}
......@@ -1539,7 +1571,9 @@ class UserPreferredContentMode {
static UserPreferredContentMode fromValue(int value) {
if (value != null)
return UserPreferredContentMode.values.firstWhere((element) => element.toValue() == value, orElse: () => null);
return UserPreferredContentMode.values.firstWhere(
(element) => element.toValue() == value,
orElse: () => null);
return null;
}
......@@ -1594,7 +1628,9 @@ class IOSUIModalPresentationStyle {
static IOSUIModalPresentationStyle fromValue(int value) {
if (value != null)
return IOSUIModalPresentationStyle.values.firstWhere((element) => element.toValue() == value, orElse: () => null);
return IOSUIModalPresentationStyle.values.firstWhere(
(element) => element.toValue() == value,
orElse: () => null);
return null;
}
......@@ -1682,7 +1718,9 @@ class IOSUIModalTransitionStyle {
static IOSUIModalTransitionStyle fromValue(int value) {
if (value != null)
return IOSUIModalTransitionStyle.values.firstWhere((element) => element.toValue() == value, orElse: () => null);
return IOSUIModalTransitionStyle.values.firstWhere(
(element) => element.toValue() == value,
orElse: () => null);
return null;
}
......@@ -1743,7 +1781,9 @@ class IOSSafariDismissButtonStyle {
static IOSSafariDismissButtonStyle fromValue(int value) {
if (value != null)
return IOSSafariDismissButtonStyle.values.firstWhere((element) => element.toValue() == value, orElse: () => null);
return IOSSafariDismissButtonStyle.values.firstWhere(
(element) => element.toValue() == value,
orElse: () => null);
return null;
}
......@@ -1788,9 +1828,7 @@ class InAppWebViewGroupOptions {
///iOS-specific options.
IOSInAppWebViewOptions ios;
InAppWebViewGroupOptions({this.crossPlatform,
this.android,
this.ios}) {
InAppWebViewGroupOptions({this.crossPlatform, this.android, this.ios}) {
this.crossPlatform = this.crossPlatform ?? InAppWebViewOptions();
this.android = this.android ?? AndroidInAppWebViewOptions();
this.ios = this.ios ?? IOSInAppWebViewOptions();
......@@ -1807,7 +1845,8 @@ class InAppWebViewGroupOptions {
}
static InAppWebViewGroupOptions fromMap(Map<String, dynamic> options) {
InAppWebViewGroupOptions inAppWebViewGroupOptions = InAppWebViewGroupOptions();
InAppWebViewGroupOptions inAppWebViewGroupOptions =
InAppWebViewGroupOptions();
inAppWebViewGroupOptions.crossPlatform =
InAppWebViewOptions.fromMap(options);
......@@ -1848,7 +1887,8 @@ class InAppBrowserClassOptions {
///WebView options.
InAppWebViewGroupOptions inAppWebViewGroupOptions;
InAppBrowserClassOptions({this.crossPlatform,
InAppBrowserClassOptions(
{this.crossPlatform,
this.android,
this.ios,
this.inAppWebViewGroupOptions}) {
......@@ -1885,7 +1925,8 @@ class InAppBrowserClassOptions {
}
static InAppBrowserClassOptions fromMap(Map<String, dynamic> options) {
InAppBrowserClassOptions inAppBrowserClassOptions = InAppBrowserClassOptions();
InAppBrowserClassOptions inAppBrowserClassOptions =
InAppBrowserClassOptions();
inAppBrowserClassOptions.crossPlatform =
InAppBrowserOptions.fromMap(options);
......@@ -1920,10 +1961,7 @@ class ChromeSafariBrowserClassOptions {
///iOS-specific options.
IOSSafariOptions ios;
ChromeSafariBrowserClassOptions({
this.android,
this.ios
}) {
ChromeSafariBrowserClassOptions({this.android, this.ios}) {
this.android = this.android ?? AndroidChromeCustomTabsOptions();
this.ios = this.ios ?? IOSSafariOptions();
}
......@@ -2000,7 +2038,9 @@ class AjaxRequestEventType {
static AjaxRequestEventType fromValue(String value) {
if (value != null)
return AjaxRequestEventType.values.firstWhere((element) => element.toValue() == value, orElse: () => null);
return AjaxRequestEventType.values.firstWhere(
(element) => element.toValue() == value,
orElse: () => null);
return null;
}
......@@ -2073,7 +2113,9 @@ class AjaxRequestReadyState {
static AjaxRequestReadyState fromValue(int value) {
if (value != null)
return AjaxRequestReadyState.values.firstWhere((element) => element.toValue() == value, orElse: () => null);
return AjaxRequestReadyState.values.firstWhere(
(element) => element.toValue() == value,
orElse: () => null);
return null;
}
......@@ -2211,7 +2253,8 @@ class AjaxRequest {
///Indicates the [AjaxRequestAction] that can be used to control the `XMLHttpRequest` request.
AjaxRequestAction action;
AjaxRequest({this.data,
AjaxRequest(
{this.data,
this.method,
this.url,
this.isAsync,
......@@ -2450,7 +2493,8 @@ class FetchRequest {
///Indicates the [FetchRequestAction] that can be used to control the request.
FetchRequestAction action;
FetchRequest({this.url,
FetchRequest(
{this.url,
this.method,
this.headers,
this.body,
......@@ -2536,7 +2580,9 @@ class ContentBlockerTriggerResourceType {
static ContentBlockerTriggerResourceType fromValue(String value) {
if (value != null)
return ContentBlockerTriggerResourceType.values.firstWhere((element) => element.toValue() == value, orElse: () => null);
return ContentBlockerTriggerResourceType.values.firstWhere(
(element) => element.toValue() == value,
orElse: () => null);
return null;
}
......@@ -2581,7 +2627,9 @@ class ContentBlockerTriggerLoadType {
static ContentBlockerTriggerLoadType fromValue(String value) {
if (value != null)
return ContentBlockerTriggerLoadType.values.firstWhere((element) => element.toValue() == value, orElse: () => null);
return ContentBlockerTriggerLoadType.values.firstWhere(
(element) => element.toValue() == value,
orElse: () => null);
return null;
}
......@@ -2618,7 +2666,9 @@ class ContentBlockerActionType {
static ContentBlockerActionType fromValue(String value) {
if (value != null)
return ContentBlockerActionType.values.firstWhere((element) => element.toValue() == value, orElse: () => null);
return ContentBlockerActionType.values.firstWhere(
(element) => element.toValue() == value,
orElse: () => null);
return null;
}
......@@ -2689,7 +2739,8 @@ class Cookie {
///**NOTE**: on Android it will be always `null`.
String path;
Cookie({@required this.name,
Cookie(
{@required this.name,
@required this.value,
this.expiresDate,
this.isSessionOnly,
......@@ -2751,7 +2802,8 @@ class PermissionRequestResponse {
///Indicate the [PermissionRequestResponseAction] to take in response of a permission request.
PermissionRequestResponseAction action;
PermissionRequestResponse({this.resources = const [],
PermissionRequestResponse(
{this.resources = const [],
this.action = PermissionRequestResponseAction.DENY});
Map<String, dynamic> toMap() {
......@@ -2812,7 +2864,9 @@ class IOSWKNavigationType {
static IOSWKNavigationType fromValue(int value) {
if (value != null)
return IOSWKNavigationType.values.firstWhere((element) => element.toValue() == value, orElse: () => null);
return IOSWKNavigationType.values.firstWhere(
(element) => element.toValue() == value,
orElse: () => null);
return null;
}
......@@ -2870,7 +2924,8 @@ class ShouldOverrideUrlLoadingRequest {
///The type of action triggering the navigation. Available only on iOS.
IOSWKNavigationType iosWKNavigationType;
ShouldOverrideUrlLoadingRequest({this.url,
ShouldOverrideUrlLoadingRequest(
{this.url,
this.method,
this.headers,
this.isForMainFrame,
......@@ -2914,7 +2969,8 @@ class OnCreateWindowRequest {
///The type of action triggering the navigation. Available only on iOS.
IOSWKNavigationType iosWKNavigationType;
OnCreateWindowRequest({this.url,
OnCreateWindowRequest(
{this.url,
this.androidIsDialog,
this.androidIsUserGesture,
this.iosWKNavigationType});
......@@ -2989,7 +3045,9 @@ class IOSWKWebsiteDataType {
static IOSWKWebsiteDataType fromValue(String value) {
if (value != null)
return IOSWKWebsiteDataType.values.firstWhere((element) => element.toValue() == value, orElse: () => null);
return IOSWKWebsiteDataType.values.firstWhere(
(element) => element.toValue() == value,
orElse: () => null);
return null;
}
......@@ -3116,7 +3174,9 @@ class InAppWebViewHitTestResultType {
static InAppWebViewHitTestResultType fromValue(int value) {
if (value != null)
return InAppWebViewHitTestResultType.values.firstWhere((element) => element.toValue() == value, orElse: () => null);
return InAppWebViewHitTestResultType.values.firstWhere(
(element) => element.toValue() == value,
orElse: () => null);
return null;
}
......@@ -3269,7 +3329,9 @@ class RendererPriority {
static RendererPriority fromValue(int value) {
if (value != null)
return RendererPriority.values.firstWhere((element) => element.toValue() == value, orElse: () => null);
return RendererPriority.values.firstWhere(
(element) => element.toValue() == value,
orElse: () => null);
return null;
}
......@@ -3318,7 +3380,8 @@ class RendererPriorityPolicy {
///If true, this flag specifies that when this WebView is not visible, it will be treated as if it had requested a priority of [RendererPriority.RENDERER_PRIORITY_WAIVED].
bool waivedWhenNotVisible;
RendererPriorityPolicy({@required this.rendererRequestedPriority,
RendererPriorityPolicy(
{@required this.rendererRequestedPriority,
@required this.waivedWhenNotVisible});
Map<String, dynamic> toMap() {
......@@ -3395,7 +3458,9 @@ class AndroidOverScrollMode {
static AndroidOverScrollMode fromValue(int value) {
if (value != null)
return AndroidOverScrollMode.values.firstWhere((element) => element.toValue() == value, orElse: () => null);
return AndroidOverScrollMode.values.firstWhere(
(element) => element.toValue() == value,
orElse: () => null);
return null;
}
......@@ -3451,7 +3516,9 @@ class AndroidScrollBarStyle {
static AndroidScrollBarStyle fromValue(int value) {
if (value != null)
return AndroidScrollBarStyle.values.firstWhere((element) => element.toValue() == value, orElse: () => null);
return AndroidScrollBarStyle.values.firstWhere(
(element) => element.toValue() == value,
orElse: () => null);
return null;
}
......@@ -3512,7 +3579,9 @@ class AndroidVerticalScrollbarPosition {
static AndroidVerticalScrollbarPosition fromValue(int value) {
if (value != null)
return AndroidVerticalScrollbarPosition.values.firstWhere((element) => element.toValue() == value, orElse: () => null);
return AndroidVerticalScrollbarPosition.values.firstWhere(
(element) => element.toValue() == value,
orElse: () => null);
return null;
}
......@@ -3698,7 +3767,9 @@ class WebStorageType {
static WebStorageType fromValue(String value) {
if (value != null)
return WebStorageType.values.firstWhere((element) => element.toValue() == value, orElse: () => null);
return WebStorageType.values.firstWhere(
(element) => element.toValue() == value,
orElse: () => null);
return null;
}
......@@ -3735,7 +3806,9 @@ class HTTPCookieSameSitePolicy {
static HTTPCookieSameSitePolicy fromValue(String value) {
if (value != null)
return HTTPCookieSameSitePolicy.values.firstWhere((element) => element.toValue() == value, orElse: () => null);
return HTTPCookieSameSitePolicy.values.firstWhere(
(element) => element.toValue() == value,
orElse: () => null);
return null;
}
......@@ -3785,7 +3858,9 @@ class AndroidSslError {
static AndroidSslError fromValue(int value) {
if (value != null)
return AndroidSslError.values.firstWhere((element) => element.toValue() == value, orElse: () => null);
return AndroidSslError.values.firstWhere(
(element) => element.toValue() == value,
orElse: () => null);
return null;
}
......@@ -3852,7 +3927,9 @@ class IOSSslError {
static IOSSslError fromValue(int value) {
if (value != null)
return IOSSslError.values.firstWhere((element) => element.toValue() == value, orElse: () => null);
return IOSSslError.values.firstWhere(
(element) => element.toValue() == value,
orElse: () => null);
return null;
}
......@@ -3918,7 +3995,9 @@ class IOSUIScrollViewContentInsetAdjustmentBehavior {
static IOSUIScrollViewContentInsetAdjustmentBehavior fromValue(int value) {
if (value != null)
return IOSUIScrollViewContentInsetAdjustmentBehavior.values.firstWhere((element) => element.toValue() == value, orElse: () => null);
return IOSUIScrollViewContentInsetAdjustmentBehavior.values.firstWhere(
(element) => element.toValue() == value,
orElse: () => null);
return null;
}
......@@ -3940,20 +4019,20 @@ class IOSUIScrollViewContentInsetAdjustmentBehavior {
}
///Automatically adjust the scroll view insets.
static const AUTOMATIC = const IOSUIScrollViewContentInsetAdjustmentBehavior
._internal(0);
static const AUTOMATIC =
const IOSUIScrollViewContentInsetAdjustmentBehavior._internal(0);
///Adjust the insets only in the scrollable directions.
static const SCROLLABLE_AXES = const IOSUIScrollViewContentInsetAdjustmentBehavior
._internal(1);
static const SCROLLABLE_AXES =
const IOSUIScrollViewContentInsetAdjustmentBehavior._internal(1);
///Do not adjust the scroll view insets.
static const NEVER = const IOSUIScrollViewContentInsetAdjustmentBehavior
._internal(2);
static const NEVER =
const IOSUIScrollViewContentInsetAdjustmentBehavior._internal(2);
///Always include the safe area insets in the content adjustment.
static const ALWAYS = const IOSUIScrollViewContentInsetAdjustmentBehavior
._internal(3);
static const ALWAYS =
const IOSUIScrollViewContentInsetAdjustmentBehavior._internal(3);
bool operator ==(value) => value == _value;
......@@ -3963,7 +4042,6 @@ class IOSUIScrollViewContentInsetAdjustmentBehavior {
///SSL certificate info (certificate details) class.
class SslCertificate {
///Name of the entity this certificate is issued by
SslCertificateDName issuedBy;
......@@ -3979,13 +4057,12 @@ class SslCertificate {
///The original source certificate, if available.
X509Certificate x509Certificate;
SslCertificate({
this.issuedBy,
SslCertificate(
{this.issuedBy,
this.issuedTo,
this.validNotAfterDate,
this.validNotBeforeDate,
this.x509Certificate
});
this.x509Certificate});
static SslCertificate fromMap(Map<String, dynamic> map) {
X509Certificate x509Certificate;
......@@ -3996,17 +4073,19 @@ class SslCertificate {
print(stacktrace);
}
return map != null ? SslCertificate(
return map != null
? SslCertificate(
issuedBy: SslCertificateDName.fromMap(
map["issuedBy"]?.cast<String, dynamic>()),
issuedTo: SslCertificateDName.fromMap(
map["issuedTo"]?.cast<String, dynamic>()),
validNotAfterDate: DateTime.fromMillisecondsSinceEpoch(
map["validNotAfterDate"]),
validNotBeforeDate: DateTime.fromMillisecondsSinceEpoch(
map["validNotBeforeDate"]),
validNotAfterDate:
DateTime.fromMillisecondsSinceEpoch(map["validNotAfterDate"]),
validNotBeforeDate:
DateTime.fromMillisecondsSinceEpoch(map["validNotBeforeDate"]),
x509Certificate: x509Certificate,
) : null;
)
: null;
}
Map<String, dynamic> toMap() {
......@@ -4049,15 +4128,20 @@ class SslCertificateDName {
SslCertificateDName(
// ignore: non_constant_identifier_names
{this.CName = "", this.DName = "", this.OName = "", this.UName = ""});
{this.CName = "",
this.DName = "",
this.OName = "",
this.UName = ""});
static SslCertificateDName fromMap(Map<String, dynamic> map) {
return map != null ? SslCertificateDName(
return map != null
? SslCertificateDName(
CName: map["CName"] ?? "",
DName: map["DName"] ?? "",
OName: map["OName"] ?? "",
UName: map["UName"] ?? "",
) : null;
)
: null;
}
Map<String, dynamic> toMap() {
......
......@@ -15,7 +15,6 @@ class Util {
} else if (colorValue.startsWith("hlsa(")) {
return Util.getColorFromHlsaString(colorValue);
} else {
/**
This part of the code is generated using the JavaScript code below on this link: https://drafts.csswg.org/css-color/#typedef-color
......@@ -33,7 +32,7 @@ class Util {
code += '}';
*/
switch(colorValue) {
switch (colorValue) {
case "aliceblue":
return Util.getColorFromHex("#f0f8ff");
case "antiquewhite":
......@@ -337,8 +336,10 @@ class Util {
static Color getColorFromHex(String hexString) {
hexString = hexString.trim();
if (hexString.length == 4) { // convert for example #f00 to #ff0000
hexString = "#" + (hexString[1] * 2) + (hexString[2] * 2) + (hexString[3] * 2);
if (hexString.length == 4) {
// convert for example #f00 to #ff0000
hexString =
"#" + (hexString[1] * 2) + (hexString[2] * 2) + (hexString[3] * 2);
}
final buffer = StringBuffer();
if (hexString.length == 6 || hexString.length == 7) buffer.write('ff');
......@@ -363,7 +364,8 @@ class Util {
.split(",")
.map((rbgValue) => rbgValue.trim())
.toList();
return Color.fromRGBO(int.parse(rgbaValues[0]), int.parse(rgbaValues[1]), int.parse(rgbaValues[2]), double.parse(rgbaValues[3]));
return Color.fromRGBO(int.parse(rgbaValues[0]), int.parse(rgbaValues[1]),
int.parse(rgbaValues[2]), double.parse(rgbaValues[3]));
}
static Color getColorFromHlsString(String hlsString) {
......@@ -385,10 +387,11 @@ class Util {
.map((rbgValue) => double.parse(rbgValue.trim()))
.toList();
var rgbaValues = hslToRgb(hlsaValues[0], hlsaValues[1], hlsaValues[2]);
return Color.fromRGBO(rgbaValues[0], rgbaValues[1], rgbaValues[2], hlsaValues[3]);
return Color.fromRGBO(
rgbaValues[0], rgbaValues[1], rgbaValues[2], hlsaValues[3]);
}
static List<num> hslToRgb(double h, double s, double l){
static List<num> hslToRgb(double h, double s, double l) {
double r, g, b;
if (s == 0) {
......@@ -396,30 +399,25 @@ class Util {
} else {
double q = l < 0.5 ? l * (1 + s) : l + s - l * s;
double p = 2 * l - q;
r = hueToRgb(p, q, h + 1/3);
r = hueToRgb(p, q, h + 1 / 3);
g = hueToRgb(p, q, h);
b = hueToRgb(p, q, h - 1/3);
b = hueToRgb(p, q, h - 1 / 3);
}
var rgb = [to255(r), to255(g), to255(b)];
return rgb;
}
static num to255(double v) {
return min(255, 256*v);
return min(255, 256 * v);
}
/// Helper method that converts hue to rgb
static double hueToRgb(double p, double q, double t) {
if (t < 0)
t += 1;
if (t > 1)
t -= 1;
if (t < 1/6)
return p + (q - p) * 6 * t;
if (t < 1/2)
return q;
if (t < 2/3)
return p + (q - p) * (2/3 - t) * 6;
if (t < 0) t += 1;
if (t > 1) t -= 1;
if (t < 1 / 6) return p + (q - p) * 6 * t;
if (t < 1 / 2) return q;
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
return p;
}
}
......@@ -54,7 +54,7 @@ class Storage {
Future<void> setItem({@required String key, @required dynamic value}) async {
var encodedValue = json.encode(value);
await _controller.evaluateJavascript(source: """
window.$webStorageType.setItem("$key", ${ value is String ? encodedValue : "JSON.stringify($encodedValue)" });
window.$webStorageType.setItem("$key", ${value is String ? encodedValue : "JSON.stringify($encodedValue)"});
""");
}
......@@ -81,10 +81,10 @@ class Storage {
}
Future<List<WebStorageItem>> getItems() async {
var webStorageItems = <WebStorageItem>[];
List<Map<dynamic, dynamic>> items = (await _controller.evaluateJavascript(source: """
List<Map<dynamic, dynamic>> items =
(await _controller.evaluateJavascript(source: """
(function() {
var webStorageItems = [];
for(var i = 0; i < window.$webStorageType.length; i++){
......@@ -105,9 +105,8 @@ class Storage {
}
for (var item in items) {
webStorageItems.add(
WebStorageItem(key: item["key"], value: item["value"])
);
webStorageItems
.add(WebStorageItem(key: item["key"], value: item["value"]));
}
return webStorageItems;
......@@ -128,9 +127,11 @@ class Storage {
}
class LocalStorage extends Storage {
LocalStorage(InAppWebViewController controller) : super(controller, WebStorageType.LOCAL_STORAGE);
LocalStorage(InAppWebViewController controller)
: super(controller, WebStorageType.LOCAL_STORAGE);
}
class SessionStorage extends Storage {
SessionStorage(InAppWebViewController controller) : super(controller, WebStorageType.SESSION_STORAGE);
SessionStorage(InAppWebViewController controller)
: super(controller, WebStorageType.SESSION_STORAGE);
}
......@@ -838,7 +838,8 @@ class IOSInAppWebViewOptions
this.isPagingEnabled = false,
this.maximumZoomScale = 1.0,
this.minimumZoomScale = 1.0,
this.contentInsetAdjustmentBehavior = IOSUIScrollViewContentInsetAdjustmentBehavior.NEVER});
this.contentInsetAdjustmentBehavior =
IOSUIScrollViewContentInsetAdjustmentBehavior.NEVER});
@override
Map<String, dynamic> toMap() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment