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

v3.4.0

parent f6a6b4a6
...@@ -21,7 +21,6 @@ class ASN1DERDecoder { ...@@ -21,7 +21,6 @@ class ASN1DERDecoder {
asn1obj.identifier = ASN1Identifier(nextValue); asn1obj.identifier = ASN1Identifier(nextValue);
if (asn1obj.identifier.isConstructed()) { if (asn1obj.identifier.isConstructed()) {
var contentData = loadSubContent(iterator: iterator); var contentData = loadSubContent(iterator: iterator);
if (contentData.isEmpty) { if (contentData.isEmpty) {
...@@ -39,9 +38,7 @@ class ASN1DERDecoder { ...@@ -39,9 +38,7 @@ class ASN1DERDecoder {
item.parent = asn1obj; item.parent = asn1obj;
} }
} else { } else {
if (asn1obj.identifier.typeClass() == ASN1IdentifierClass.UNIVERSAL) { if (asn1obj.identifier.typeClass() == ASN1IdentifierClass.UNIVERSAL) {
var contentData = loadSubContent(iterator: iterator); var contentData = loadSubContent(iterator: iterator);
asn1obj.encoded = Uint8List.fromList(contentData); asn1obj.encoded = Uint8List.fromList(contentData);
...@@ -52,75 +49,62 @@ class ASN1DERDecoder { ...@@ -52,75 +49,62 @@ class ASN1DERDecoder {
if (tagNumber == ASN1IdentifierTagNumber.END_OF_CONTENT) { if (tagNumber == ASN1IdentifierTagNumber.END_OF_CONTENT) {
return result; return result;
} } else if (tagNumber == ASN1IdentifierTagNumber.BOOLEAN) {
else if (tagNumber == ASN1IdentifierTagNumber.BOOLEAN) {
var value = contentData.length > 0 ? contentData.first : null; var value = contentData.length > 0 ? contentData.first : null;
if (value != null) { if (value != null) {
asn1obj.value = value > 0 ? true : false; asn1obj.value = value > 0 ? true : false;
} }
} } else if (tagNumber == ASN1IdentifierTagNumber.INTEGER) {
else if (tagNumber == ASN1IdentifierTagNumber.INTEGER) {
while (contentData.length > 0 && contentData.first == 0) { while (contentData.length > 0 && contentData.first == 0) {
contentData.removeAt(0); // remove not significant digit contentData.removeAt(0); // remove not significant digit
} }
asn1obj.value = contentData; asn1obj.value = contentData;
} } else if (tagNumber == ASN1IdentifierTagNumber.NULL) {
else if (tagNumber == ASN1IdentifierTagNumber.NULL) {
asn1obj.value = null; asn1obj.value = null;
} } else if (tagNumber == ASN1IdentifierTagNumber.OBJECT_IDENTIFIER) {
else if (tagNumber == ASN1IdentifierTagNumber.OBJECT_IDENTIFIER) {
asn1obj.value = decodeOid(contentData: contentData); asn1obj.value = decodeOid(contentData: contentData);
} } else if ([
else if ([
ASN1IdentifierTagNumber.UTF8_STRING, ASN1IdentifierTagNumber.UTF8_STRING,
ASN1IdentifierTagNumber.PRINTABLE_STRING, ASN1IdentifierTagNumber.PRINTABLE_STRING,
ASN1IdentifierTagNumber.NUMERIC_STRING, ASN1IdentifierTagNumber.NUMERIC_STRING,
ASN1IdentifierTagNumber.GENERAL_STRING, ASN1IdentifierTagNumber.GENERAL_STRING,
ASN1IdentifierTagNumber.UNIVERSAL_STRING, ASN1IdentifierTagNumber.UNIVERSAL_STRING,
ASN1IdentifierTagNumber.CHARACTER_STRING, ASN1IdentifierTagNumber.CHARACTER_STRING,
ASN1IdentifierTagNumber.T61_STRING].contains(tagNumber)) { ASN1IdentifierTagNumber.T61_STRING
].contains(tagNumber)) {
asn1obj.value = utf8.decode(contentData, allowMalformed: true); asn1obj.value = utf8.decode(contentData, allowMalformed: true);
} } else if (tagNumber == ASN1IdentifierTagNumber.BMP_STRING) {
else if (tagNumber == ASN1IdentifierTagNumber.BMP_STRING) {
asn1obj.value = String.fromCharCodes(contentData); asn1obj.value = String.fromCharCodes(contentData);
} } else if ([
else if ([
ASN1IdentifierTagNumber.VISIBLE_STRING, ASN1IdentifierTagNumber.VISIBLE_STRING,
ASN1IdentifierTagNumber.IA5_STRING ASN1IdentifierTagNumber.IA5_STRING
].contains(tagNumber)) { ].contains(tagNumber)) {
asn1obj.value = ascii.decode(contentData, allowInvalid: true); asn1obj.value = ascii.decode(contentData, allowInvalid: true);
} } else if (tagNumber == ASN1IdentifierTagNumber.UTC_TIME) {
else if (tagNumber == ASN1IdentifierTagNumber.UTC_TIME) {
asn1obj.value = utcTimeToDate(contentData: contentData); asn1obj.value = utcTimeToDate(contentData: contentData);
} } else if (tagNumber == ASN1IdentifierTagNumber.GENERALIZED_TIME) {
else if (tagNumber == ASN1IdentifierTagNumber.GENERALIZED_TIME) {
asn1obj.value = generalizedTimeToDate(contentData: contentData); asn1obj.value = generalizedTimeToDate(contentData: contentData);
} } else if (tagNumber == ASN1IdentifierTagNumber.BIT_STRING) {
else if (tagNumber == ASN1IdentifierTagNumber.BIT_STRING) {
if (contentData.length > 0) { if (contentData.length > 0) {
contentData.removeAt(0); // unused bits contentData.removeAt(0); // unused bits
} }
asn1obj.value = contentData; asn1obj.value = contentData;
} } else if (tagNumber == ASN1IdentifierTagNumber.OCTET_STRING) {
else if (tagNumber == ASN1IdentifierTagNumber.OCTET_STRING) {
try { try {
var subIterator = contentData.iterator; var subIterator = contentData.iterator;
asn1obj.sub = parse(iterator: subIterator); asn1obj.sub = parse(iterator: subIterator);
} catch (e) { } catch (e) {
var str; var str;
try { try {
str = utf8.decode(contentData); str = utf8.decode(contentData);
} catch(e) {} } catch (e) {}
if (str != null) { if (str != null) {
asn1obj.value = str; asn1obj.value = str;
} else { } else {
asn1obj.value = contentData; asn1obj.value = contentData;
} }
} }
} } else {
else {
// print("unsupported tag: ${asn1obj.identifier.tagNumber()}"); // print("unsupported tag: ${asn1obj.identifier.tagNumber()}");
asn1obj.value = contentData; asn1obj.value = contentData;
} }
...@@ -132,7 +116,7 @@ class ASN1DERDecoder { ...@@ -132,7 +116,7 @@ class ASN1DERDecoder {
var str; var str;
try { try {
str = utf8.decode(contentData); str = utf8.decode(contentData);
} catch(e) {} } catch (e) {}
if (str != null) { if (str != null) {
asn1obj.value = str; asn1obj.value = str;
} else { } else {
...@@ -150,8 +134,8 @@ class ASN1DERDecoder { ...@@ -150,8 +134,8 @@ class ASN1DERDecoder {
if (iterator.moveNext()) { if (iterator.moveNext()) {
var first = iterator.current; var first = iterator.current;
if (first != null) { if (first != null) {
if ((first & 0x80) != 0) {
if ((first & 0x80) != 0) { // long // long
var octetsToRead = first - 0x80; var octetsToRead = first - 0x80;
var data = <int>[]; var data = <int>[];
...@@ -165,11 +149,10 @@ class ASN1DERDecoder { ...@@ -165,11 +149,10 @@ class ASN1DERDecoder {
} }
return toIntValue(data) ?? BigInt.from(0); return toIntValue(data) ?? BigInt.from(0);
} else {
} else { // short // short
return BigInt.from(first); return BigInt.from(first);
} }
} }
} }
return BigInt.from(0); return BigInt.from(0);
...@@ -251,7 +234,7 @@ class ASN1DERDecoder { ...@@ -251,7 +234,7 @@ class ASN1DERDecoder {
String utc; String utc;
try { try {
utc = utf8.decode(contentData); utc = utf8.decode(contentData);
} catch(e) {} } catch (e) {}
if (utc == null) { if (utc == null) {
return null; return null;
} }
...@@ -268,36 +251,30 @@ class ASN1DERDecoder { ...@@ -268,36 +251,30 @@ class ASN1DERDecoder {
int end; int end;
String c; String c;
// not just YYMMDDhhmmZ // not just YYMMDDhhmmZ
if(utc.length > 11) { if (utc.length > 11) {
// get character after minutes // get character after minutes
c = utc[10]; c = utc[10];
end = 10; end = 10;
// see if seconds are present // see if seconds are present
if(c != '+' && c != '-') { if (c != '+' && c != '-') {
// get seconds // get seconds
ss = int.parse(utc.substring(10, 12), radix: 10); ss = int.parse(utc.substring(10, 12), radix: 10);
end += 2; end += 2;
} }
} }
var date = DateTime.utc( var date = DateTime.utc(year, MM, DD, hh, mm, ss, 0);
year,
MM, if (end != null) {
DD,
hh,
mm,
ss,
0
);
if(end != null) {
// get +/- after end of time // get +/- after end of time
c = utc[end]; c = utc[end];
if(c == '+' || c == '-') { if (c == '+' || c == '-') {
// get hours+minutes offset // get hours+minutes offset
var hhoffset = int.parse(utc.substring(end + 1, end + 1 + 2), radix: 10); var hhoffset =
var mmoffset = int.parse(utc.substring(end + 4, end + 4 + 2), radix: 10); 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 // calculate offset in milliseconds
var offset = hhoffset * 60 + mmoffset; var offset = hhoffset * 60 + mmoffset;
...@@ -305,7 +282,7 @@ class ASN1DERDecoder { ...@@ -305,7 +282,7 @@ class ASN1DERDecoder {
var offsetDuration = Duration(milliseconds: offset); var offsetDuration = Duration(milliseconds: offset);
// apply offset // apply offset
if(c == '+') { if (c == '+') {
date.subtract(offsetDuration); date.subtract(offsetDuration);
} else { } else {
date.add(offsetDuration); date.add(offsetDuration);
...@@ -345,7 +322,7 @@ class ASN1DERDecoder { ...@@ -345,7 +322,7 @@ class ASN1DERDecoder {
String gentime; String gentime;
try { try {
gentime = utf8.decode(contentData); gentime = utf8.decode(contentData);
} catch(e) {} } catch (e) {}
if (gentime == null) { if (gentime == null) {
return null; return null;
} }
...@@ -362,23 +339,25 @@ class ASN1DERDecoder { ...@@ -362,23 +339,25 @@ class ASN1DERDecoder {
var offset = 0; var offset = 0;
var isUTC = false; var isUTC = false;
if(gentime[gentime.length - 1] == 'Z') { if (gentime[gentime.length - 1] == 'Z') {
isUTC = true; isUTC = true;
} }
var end = gentime.length - 5; var end = gentime.length - 5;
var c = gentime[end]; var c = gentime[end];
if(c == '+' || c == '-') { if (c == '+' || c == '-') {
// get hours+minutes offset // get hours+minutes offset
var hhoffset = int.parse(gentime.substring(end + 1, end + 1 + 2), radix: 10); var hhoffset =
var mmoffset = int.parse(gentime.substring(end + 4, end + 4 + 2), radix: 10); 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 // calculate offset in milliseconds
offset = hhoffset * 60 + mmoffset; offset = hhoffset * 60 + mmoffset;
offset *= 60000; offset *= 60000;
// apply offset // apply offset
if(c == '+') { if (c == '+') {
offset *= -1; offset *= -1;
} }
...@@ -386,26 +365,17 @@ class ASN1DERDecoder { ...@@ -386,26 +365,17 @@ class ASN1DERDecoder {
} }
// check for second fraction // check for second fraction
if(gentime[14] == '.') { if (gentime[14] == '.') {
fff = double.parse(gentime.substring(14)) * 1000; fff = double.parse(gentime.substring(14)) * 1000;
} }
var date = DateTime.utc( var date = DateTime.utc(YYYY, MM, DD, hh, mm, ss, fff.toInt());
YYYY,
MM, if (isUTC) {
DD,
hh,
mm,
ss,
fff.toInt()
);
if(isUTC) {
var offsetDuration = Duration(milliseconds: offset); var offsetDuration = Duration(milliseconds: offset);
date.add(offsetDuration); date.add(offsetDuration);
} }
return date; return date;
} }
} }
...@@ -418,15 +388,11 @@ BigInt toIntValue(List<int> data) { ...@@ -418,15 +388,11 @@ BigInt toIntValue(List<int> data) {
BigInt value = BigInt.from(0); BigInt value = BigInt.from(0);
for (var index = 0; index < data.length; index++) { for (var index = 0; index < data.length; index++) {
var byte = data[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; return value;
} }
class ASN1OutOfBufferError extends Error { class ASN1OutOfBufferError extends Error {}
}
class ASN1ParseError extends Error {
} class ASN1ParseError extends Error {}
\ No newline at end of file
...@@ -21,32 +21,45 @@ class ASN1DistinguishedNames { ...@@ -21,32 +21,45 @@ class ASN1DistinguishedNames {
static ASN1DistinguishedNames fromValue(String oid) { static ASN1DistinguishedNames fromValue(String oid) {
if (oid != null) 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; return null;
} }
String oid() => _oid; String oid() => _oid;
String representation() => _representation; String representation() => _representation;
@override @override
String toString() => "($_oid, $_representation)"; String toString() => "($_oid, $_representation)";
static const COMMON_NAME = const ASN1DistinguishedNames._internal("2.5.4.3", "CN"); static const COMMON_NAME =
static const DN_QUALIFIER = const ASN1DistinguishedNames._internal("2.5.4.46", "DNQ"); const ASN1DistinguishedNames._internal("2.5.4.3", "CN");
static const SERIAL_NUMBER = const ASN1DistinguishedNames._internal("2.5.4.5", "SERIALNUMBER"); static const DN_QUALIFIER =
static const GIVEN_NAME = const ASN1DistinguishedNames._internal("2.5.4.42", "GIVENNAME"); const ASN1DistinguishedNames._internal("2.5.4.46", "DNQ");
static const SURNAME = const ASN1DistinguishedNames._internal("2.5.4.4", "SURNAME"); static const SERIAL_NUMBER =
static const ORGANIZATIONAL_UNIT_NAME = const ASN1DistinguishedNames._internal("2.5.4.11", "OU"); const ASN1DistinguishedNames._internal("2.5.4.5", "SERIALNUMBER");
static const ORGANIZATION_NAME = const ASN1DistinguishedNames._internal("2.5.4.10", "O"); static const GIVEN_NAME =
static const STREET_ADDRESS = const ASN1DistinguishedNames._internal("2.5.4.9", "STREET"); const ASN1DistinguishedNames._internal("2.5.4.42", "GIVENNAME");
static const LOCALITY_NAME = const ASN1DistinguishedNames._internal("2.5.4.7", "L"); static const SURNAME =
static const STATE_OR_PROVINCE_NAME = const ASN1DistinguishedNames._internal("2.5.4.8", "ST"); const ASN1DistinguishedNames._internal("2.5.4.4", "SURNAME");
static const COUNTRY_NAME = const ASN1DistinguishedNames._internal("2.5.4.6", "C"); static const ORGANIZATIONAL_UNIT_NAME =
static const EMAIL = const ASN1DistinguishedNames._internal("1.2.840.113549.1.9.1", "E"); 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; bool operator ==(value) => value == _oid;
@override @override
int get hashCode => _oid.hashCode; int get hashCode => _oid.hashCode;
} }
\ No newline at end of file
...@@ -12,7 +12,9 @@ class ASN1IdentifierClass { ...@@ -12,7 +12,9 @@ class ASN1IdentifierClass {
static ASN1IdentifierClass fromValue(int value) { static ASN1IdentifierClass fromValue(int value) {
if (value != null) 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; return null;
} }
...@@ -81,41 +83,45 @@ class ASN1IdentifierTagNumber { ...@@ -81,41 +83,45 @@ class ASN1IdentifierTagNumber {
static ASN1IdentifierTagNumber fromValue(int value) { static ASN1IdentifierTagNumber fromValue(int value) {
if (value != null) 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; return null;
} }
int toValue() => _value; int toValue() => _value;
static const END_OF_CONTENT = const ASN1IdentifierTagNumber._internal(0x00); static const END_OF_CONTENT = const ASN1IdentifierTagNumber._internal(0x00);
static const BOOLEAN = const ASN1IdentifierTagNumber._internal(0x01); static const BOOLEAN = const ASN1IdentifierTagNumber._internal(0x01);
static const INTEGER = const ASN1IdentifierTagNumber._internal(0x02); static const INTEGER = const ASN1IdentifierTagNumber._internal(0x02);
static const BIT_STRING = const ASN1IdentifierTagNumber._internal(0x03); static const BIT_STRING = const ASN1IdentifierTagNumber._internal(0x03);
static const OCTET_STRING = const ASN1IdentifierTagNumber._internal(0x04); static const OCTET_STRING = const ASN1IdentifierTagNumber._internal(0x04);
static const NULL = const ASN1IdentifierTagNumber._internal(0x05); static const NULL = const ASN1IdentifierTagNumber._internal(0x05);
static const OBJECT_IDENTIFIER = const ASN1IdentifierTagNumber._internal(0x06); static const OBJECT_IDENTIFIER =
static const OBJECT_DESCRIPTOR = const ASN1IdentifierTagNumber._internal(0x07); const ASN1IdentifierTagNumber._internal(0x06);
static const EXTERNAL = const ASN1IdentifierTagNumber._internal(0x08); static const OBJECT_DESCRIPTOR =
static const READ = const ASN1IdentifierTagNumber._internal(0x09); const ASN1IdentifierTagNumber._internal(0x07);
static const ENUMERATED = const ASN1IdentifierTagNumber._internal(0x0A); static const EXTERNAL = const ASN1IdentifierTagNumber._internal(0x08);
static const EMBEDDED_PDV = const ASN1IdentifierTagNumber._internal(0x0B); static const READ = const ASN1IdentifierTagNumber._internal(0x09);
static const UTF8_STRING = const ASN1IdentifierTagNumber._internal(0x0C); static const ENUMERATED = const ASN1IdentifierTagNumber._internal(0x0A);
static const RELATIVE_OID = const ASN1IdentifierTagNumber._internal(0x0D); static const EMBEDDED_PDV = const ASN1IdentifierTagNumber._internal(0x0B);
static const SEQUENCE = const ASN1IdentifierTagNumber._internal(0x10); static const UTF8_STRING = const ASN1IdentifierTagNumber._internal(0x0C);
static const SET = const ASN1IdentifierTagNumber._internal(0x11); static const RELATIVE_OID = const ASN1IdentifierTagNumber._internal(0x0D);
static const NUMERIC_STRING = const ASN1IdentifierTagNumber._internal(0x12); static const SEQUENCE = const ASN1IdentifierTagNumber._internal(0x10);
static const PRINTABLE_STRING = const ASN1IdentifierTagNumber._internal(0x13); static const SET = const ASN1IdentifierTagNumber._internal(0x11);
static const T61_STRING = const ASN1IdentifierTagNumber._internal(0x14); static const NUMERIC_STRING = const ASN1IdentifierTagNumber._internal(0x12);
static const VIDEOTEX_STRING = const ASN1IdentifierTagNumber._internal(0x15); static const PRINTABLE_STRING = const ASN1IdentifierTagNumber._internal(0x13);
static const IA5_STRING = const ASN1IdentifierTagNumber._internal(0x16); static const T61_STRING = const ASN1IdentifierTagNumber._internal(0x14);
static const UTC_TIME = const ASN1IdentifierTagNumber._internal(0x17); static const VIDEOTEX_STRING = const ASN1IdentifierTagNumber._internal(0x15);
static const GENERALIZED_TIME = const ASN1IdentifierTagNumber._internal(0x18); static const IA5_STRING = const ASN1IdentifierTagNumber._internal(0x16);
static const GRAPHIC_STRING = const ASN1IdentifierTagNumber._internal(0x19); static const UTC_TIME = const ASN1IdentifierTagNumber._internal(0x17);
static const VISIBLE_STRING = const ASN1IdentifierTagNumber._internal(0x1A); static const GENERALIZED_TIME = const ASN1IdentifierTagNumber._internal(0x18);
static const GENERAL_STRING = const ASN1IdentifierTagNumber._internal(0x1B); static const GRAPHIC_STRING = const ASN1IdentifierTagNumber._internal(0x19);
static const UNIVERSAL_STRING = const ASN1IdentifierTagNumber._internal(0x1C); static const VISIBLE_STRING = const ASN1IdentifierTagNumber._internal(0x1A);
static const CHARACTER_STRING = const ASN1IdentifierTagNumber._internal(0x1D); static const GENERAL_STRING = const ASN1IdentifierTagNumber._internal(0x1B);
static const BMP_STRING = const ASN1IdentifierTagNumber._internal(0x1E); static const UNIVERSAL_STRING = const ASN1IdentifierTagNumber._internal(0x1C);
static const CHARACTER_STRING = const ASN1IdentifierTagNumber._internal(0x1D);
static const BMP_STRING = const ASN1IdentifierTagNumber._internal(0x1E);
String toString() { String toString() {
switch (this.toValue()) { switch (this.toValue()) {
...@@ -200,11 +206,16 @@ class ASN1Identifier { ...@@ -200,11 +206,16 @@ class ASN1Identifier {
} }
ASN1IdentifierTagNumber tagNumber() { ASN1IdentifierTagNumber tagNumber() {
return ASN1IdentifierTagNumber.fromValue(rawValue & 0x1F) ?? ASN1IdentifierTagNumber.END_OF_CONTENT; return ASN1IdentifierTagNumber.fromValue(rawValue & 0x1F) ??
ASN1IdentifierTagNumber.END_OF_CONTENT;
} }
ASN1IdentifierClass typeClass() { 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()) { if ((rawValue & tc.toValue()) == tc.toValue()) {
return tc; return tc;
} }
...@@ -226,4 +237,4 @@ class ASN1Identifier { ...@@ -226,4 +237,4 @@ class ASN1Identifier {
String toString() { String toString() {
return description; return description;
} }
} }
\ No newline at end of file
...@@ -46,12 +46,12 @@ class ASN1Object { ...@@ -46,12 +46,12 @@ class ASN1Object {
ASN1Object findOid({OID oid, String oidValue}) { ASN1Object findOid({OID oid, String oidValue}) {
oidValue = oid != null ? oid.toValue() : oidValue; oidValue = oid != null ? oid.toValue() : oidValue;
for (var child in (sub ?? <ASN1Object>[])) { for (var child in (sub ?? <ASN1Object>[])) {
if (child.identifier?.tagNumber() == ASN1IdentifierTagNumber.OBJECT_IDENTIFIER) { if (child.identifier?.tagNumber() ==
ASN1IdentifierTagNumber.OBJECT_IDENTIFIER) {
if (child.value == oidValue) { if (child.value == oidValue) {
return child; return child;
} }
} } else {
else {
var result = child.findOid(oidValue: oidValue); var result = child.findOid(oidValue: oidValue);
if (result != null) { if (result != null) {
return result; return result;
...@@ -66,22 +66,23 @@ class ASN1Object { ...@@ -66,22 +66,23 @@ class ASN1Object {
} }
String printAsn1({insets = ""}) { String printAsn1({insets = ""}) {
var output = insets; var output = insets;
output += identifier?.description?.toUpperCase() ?? ""; output += identifier?.description?.toUpperCase() ?? "";
output += (value != null ? ": $value" : ""); output += (value != null ? ": $value" : "");
if (identifier?.typeClass() == ASN1IdentifierClass.UNIVERSAL && identifier?.tagNumber() == ASN1IdentifierTagNumber.OBJECT_IDENTIFIER) { if (identifier?.typeClass() == ASN1IdentifierClass.UNIVERSAL &&
var descr = OID.fromValue(value?.toString() ?? "")?.name(); identifier?.tagNumber() == ASN1IdentifierTagNumber.OBJECT_IDENTIFIER) {
if (descr != null) { var descr = OID.fromValue(value?.toString() ?? "")?.name();
output += " ($descr)"; if (descr != null) {
} output += " ($descr)";
}
output += sub != null && sub.length > 0 ? " {" : "";
output += "\n";
for (var item in (sub ?? <ASN1Object>[])) {
output += item.printAsn1(insets: insets + " ");
} }
output += sub != null && sub.length > 0 ? "}\n" : ""; }
return output; output += sub != null && sub.length > 0 ? " {" : "";
output += "\n";
for (var item in (sub ?? <ASN1Object>[])) {
output += item.printAsn1(insets: insets + " ");
}
output += sub != null && sub.length > 0 ? "}\n" : "";
return output;
} }
@override @override
...@@ -95,4 +96,4 @@ class ASN1Object { ...@@ -95,4 +96,4 @@ class ASN1Object {
} }
return null; return null;
} }
} }
\ No newline at end of file
...@@ -16,7 +16,8 @@ class KeyUsage { ...@@ -16,7 +16,8 @@ class KeyUsage {
].toSet(); ].toSet();
static KeyUsage fromIndex(int value) { 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; int toValue() => _value;
......
...@@ -103,7 +103,8 @@ class OID { ...@@ -103,7 +103,8 @@ class OID {
].toSet(); ].toSet();
static OID fromValue(String value) { 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; String toValue() => _value;
...@@ -122,29 +123,40 @@ class OID { ...@@ -122,29 +123,40 @@ class OID {
static const ecdsaWithSHA256 = const OID._internal("1.2.840.10045.4.3.2"); 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 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 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 md2WithRSAEncryption =
static const md4WithRSAEncryption = const OID._internal("1.2.840.113549.1.1.3"); const OID._internal("1.2.840.113549.1.1.2");
static const md5WithRSAEncryption = const OID._internal("1.2.840.113549.1.1.4"); static const md4WithRSAEncryption =
static const sha1WithRSAEncryption = const OID._internal("1.2.840.113549.1.1.5"); 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 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 mgf1 = const OID._internal(".2.840.113549.1.1.8");
static const pSpecified = const OID._internal(".2.840.113549.1.1.9"); 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 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 sha256WithRSAEncryption =
static const sha384WithRSAEncryption = const OID._internal("1.2.840.113549.1.1.12"); const OID._internal("1.2.840.113549.1.1.11");
static const sha512WithRSAEncryption = const OID._internal("1.2.840.113549.1.1.13"); 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 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 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 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 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 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 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 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 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 certificateExtension =
static const jurisdictionOfIncorporationSP = const OID._internal("1.3.6.1.4.1.311.60.2.1.2"); const OID._internal("1.3.6.1.4.1.11129.2.4.2");
static const jurisdictionOfIncorporationC = const OID._internal("1.3.6.1.4.1.311.60.2.1.3"); 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 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 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"); static const cps = const OID._internal("1.3.6.1.5.5.7.2.1");
...@@ -160,7 +172,8 @@ class OID { ...@@ -160,7 +172,8 @@ class OID {
static const sha384 = const OID._internal("2.16.840.1.101.3.4.2.2"); 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 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 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 extendedValidation = const OID._internal("2.23.140.1.1");
static const organizationValidated = const OID._internal("2.23.140.1.2.2"); static const organizationValidated = const OID._internal("2.23.140.1.2.2");
static const subjectKeyIdentifier = const OID._internal("2.5.29.14"); static const subjectKeyIdentifier = const OID._internal("2.5.29.14");
......
...@@ -322,7 +322,11 @@ class X509Certificate { ...@@ -322,7 +322,11 @@ class X509Certificate {
///Gets the certificate constraints path length from the ///Gets the certificate constraints path length from the
///critical BasicConstraints extension, (OID = 2.5.29.19). ///critical BasicConstraints extension, (OID = 2.5.29.19).
int get basicConstraints { 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 != null) {
if (sub.value is List<int>) { if (sub.value is List<int>) {
return (sub.value as List<int>).length; return (sub.value as List<int>).length;
...@@ -333,31 +337,60 @@ class X509Certificate { ...@@ -333,31 +337,60 @@ class X509Certificate {
///Gets the raw bits from the Subject Key Identifier (SKID) extension, (OID = 2.5.29.14). ///Gets the raw bits from the Subject Key Identifier (SKID) extension, (OID = 2.5.29.14).
List<int> get subjectKeyIdentifier => 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). ///Gets the raw bits from the Authority Key Identifier extension, (OID = 2.5.29.35).
List<int> get authorityKeyIdentifier => 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). ///Gets the list of certificate policies from the CertificatePolicies extension, (OID = 2.5.29.32).
List<String> get certificatePolicies => 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). ///Gets the list of CRL distribution points from the CRLDistributionPoints extension, (OID = 2.5.29.31).
List<String> get cRLDistributionPoints => 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 ///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 ///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). ///from the AuthorityInfoAccess extension, (OID = 1.3.6.1.5.5.5.7.1.1).
Map<String, String> get authorityInfoAccess { Map<String, String> get authorityInfoAccess {
var result = <String, String>{}; 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) { if (sub != null) {
sub.forEach((element) { sub.forEach((element) {
if (element.subCount() > 1) { if (element.subCount() > 1) {
result.putIfAbsent(element.subAtIndex(0).value, result.putIfAbsent(
() => element.subAtIndex(1).value); element.subAtIndex(0).value, () => element.subAtIndex(1).value);
} }
}); });
} }
...@@ -413,8 +446,6 @@ class X509Certificate { ...@@ -413,8 +446,6 @@ class X509Certificate {
result += quote; result += quote;
} }
} }
} }
} }
return result; return result;
......
...@@ -52,4 +52,4 @@ class X509Extension { ...@@ -52,4 +52,4 @@ class X509Extension {
} }
return result; return result;
} }
} }
\ No newline at end of file
...@@ -25,11 +25,13 @@ class X509PublicKey { ...@@ -25,11 +25,13 @@ class X509PublicKey {
} else if (oid == OID.rsaEncryption) { } else if (oid == OID.rsaEncryption) {
List<ASN1Object> publicKeyAsn1Objects; List<ASN1Object> publicKeyAsn1Objects;
try { try {
publicKeyAsn1Objects = ASN1DERDecoder.decode(data: keyData.toList(growable: true)); publicKeyAsn1Objects =
} catch(e) {} ASN1DERDecoder.decode(data: keyData.toList(growable: true));
} catch (e) {}
if (publicKeyAsn1Objects != null && publicKeyAsn1Objects.length > 0) { if (publicKeyAsn1Objects != null && publicKeyAsn1Objects.length > 0) {
var publicKeyModulus = publicKeyAsn1Objects.first?.subAtIndex(0)?.value; var publicKeyModulus =
publicKeyAsn1Objects.first?.subAtIndex(0)?.value;
if (publicKeyModulus != null) { if (publicKeyModulus != null) {
return Uint8List.fromList(publicKeyModulus); return Uint8List.fromList(publicKeyModulus);
} }
...@@ -51,4 +53,4 @@ class X509PublicKey { ...@@ -51,4 +53,4 @@ class X509PublicKey {
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
return toMap(); return toMap();
} }
} }
\ No newline at end of file
...@@ -84,7 +84,8 @@ class CookieManager { ...@@ -84,7 +84,8 @@ class CookieManager {
expiresDate: cookieListMap[i]["expiresDate"], expiresDate: cookieListMap[i]["expiresDate"],
isSessionOnly: cookieListMap[i]["isSessionOnly"], isSessionOnly: cookieListMap[i]["isSessionOnly"],
domain: cookieListMap[i]["domain"], domain: cookieListMap[i]["domain"],
sameSite: HTTPCookieSameSitePolicy.fromValue(cookieListMap[i]["sameSite"]), sameSite:
HTTPCookieSameSitePolicy.fromValue(cookieListMap[i]["sameSite"]),
isSecure: cookieListMap[i]["isSecure"], isSecure: cookieListMap[i]["isSecure"],
isHttpOnly: cookieListMap[i]["isHttpOnly"], isHttpOnly: cookieListMap[i]["isHttpOnly"],
path: cookieListMap[i]["path"])); path: cookieListMap[i]["path"]));
...@@ -111,7 +112,8 @@ class CookieManager { ...@@ -111,7 +112,8 @@ class CookieManager {
expiresDate: cookies[i]["expiresDate"], expiresDate: cookies[i]["expiresDate"],
isSessionOnly: cookies[i]["isSessionOnly"], isSessionOnly: cookies[i]["isSessionOnly"],
domain: cookies[i]["domain"], domain: cookies[i]["domain"],
sameSite: HTTPCookieSameSitePolicy.fromValue(cookies[i]["sameSite"]), sameSite:
HTTPCookieSameSitePolicy.fromValue(cookies[i]["sameSite"]),
isSecure: cookies[i]["isSecure"], isSecure: cookies[i]["isSecure"],
isHttpOnly: cookies[i]["isHttpOnly"], isHttpOnly: cookies[i]["isHttpOnly"],
path: cookies[i]["path"]); path: cookies[i]["path"]);
......
...@@ -31,7 +31,8 @@ class HttpAuthCredentialDatabase { ...@@ -31,7 +31,8 @@ class HttpAuthCredentialDatabase {
///Gets a map list of all HTTP auth credentials saved. ///Gets a map list of all HTTP auth credentials saved.
///Each map contains the key `protectionSpace` of type [ProtectionSpace] ///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`. ///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>{}; Map<String, dynamic> args = <String, dynamic>{};
List<dynamic> allCredentials = List<dynamic> allCredentials =
await _channel.invokeMethod('getAllAuthCredentials', args); await _channel.invokeMethod('getAllAuthCredentials', args);
...@@ -41,20 +42,17 @@ class HttpAuthCredentialDatabase { ...@@ -41,20 +42,17 @@ class HttpAuthCredentialDatabase {
for (Map<dynamic, dynamic> map in allCredentials) { for (Map<dynamic, dynamic> map in allCredentials) {
Map<dynamic, dynamic> protectionSpace = map["protectionSpace"]; Map<dynamic, dynamic> protectionSpace = map["protectionSpace"];
List<dynamic> credentials = map["credentials"]; List<dynamic> credentials = map["credentials"];
result.add( result.add(ProtectionSpaceHttpAuthCredentials(
ProtectionSpaceHttpAuthCredentials( protectionSpace: ProtectionSpace(
protectionSpace: ProtectionSpace( host: protectionSpace["host"],
host: protectionSpace["host"], protocol: protectionSpace["protocol"],
protocol: protectionSpace["protocol"], realm: protectionSpace["realm"],
realm: protectionSpace["realm"], port: protectionSpace["port"]),
port: protectionSpace["port"]), credentials: credentials
credentials: credentials .map((credential) => HttpAuthCredential(
.map((credential) => HttpAuthCredential(
username: credential["username"], username: credential["username"],
password: credential["password"])) password: credential["password"]))
.toList() .toList()));
)
);
} }
return result; return result;
} }
......
...@@ -291,7 +291,7 @@ class _InAppWebViewState extends State<InAppWebView> { ...@@ -291,7 +291,7 @@ class _InAppWebViewState extends State<InAppWebView> {
if (gestureRecognizers == null) { if (gestureRecognizers == null) {
gestureRecognizers = <Factory<OneSequenceGestureRecognizer>>[ gestureRecognizers = <Factory<OneSequenceGestureRecognizer>>[
Factory<OneSequenceGestureRecognizer>( Factory<OneSequenceGestureRecognizer>(
() => EagerGestureRecognizer(), () => EagerGestureRecognizer(),
), ),
].toSet(); ].toSet();
} }
......
This diff is collapsed.
This diff is collapsed.
...@@ -15,7 +15,6 @@ class Util { ...@@ -15,7 +15,6 @@ class Util {
} else if (colorValue.startsWith("hlsa(")) { } else if (colorValue.startsWith("hlsa(")) {
return Util.getColorFromHlsaString(colorValue); return Util.getColorFromHlsaString(colorValue);
} else { } else {
/** /**
This part of the code is generated using the JavaScript code below on this link: https://drafts.csswg.org/css-color/#typedef-color 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 { ...@@ -33,7 +32,7 @@ class Util {
code += '}'; code += '}';
*/ */
switch(colorValue) { switch (colorValue) {
case "aliceblue": case "aliceblue":
return Util.getColorFromHex("#f0f8ff"); return Util.getColorFromHex("#f0f8ff");
case "antiquewhite": case "antiquewhite":
...@@ -337,8 +336,10 @@ class Util { ...@@ -337,8 +336,10 @@ class Util {
static Color getColorFromHex(String hexString) { static Color getColorFromHex(String hexString) {
hexString = hexString.trim(); hexString = hexString.trim();
if (hexString.length == 4) { // convert for example #f00 to #ff0000 if (hexString.length == 4) {
hexString = "#" + (hexString[1] * 2) + (hexString[2] * 2) + (hexString[3] * 2); // convert for example #f00 to #ff0000
hexString =
"#" + (hexString[1] * 2) + (hexString[2] * 2) + (hexString[3] * 2);
} }
final buffer = StringBuffer(); final buffer = StringBuffer();
if (hexString.length == 6 || hexString.length == 7) buffer.write('ff'); if (hexString.length == 6 || hexString.length == 7) buffer.write('ff');
...@@ -363,7 +364,8 @@ class Util { ...@@ -363,7 +364,8 @@ class Util {
.split(",") .split(",")
.map((rbgValue) => rbgValue.trim()) .map((rbgValue) => rbgValue.trim())
.toList(); .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) { static Color getColorFromHlsString(String hlsString) {
...@@ -385,10 +387,11 @@ class Util { ...@@ -385,10 +387,11 @@ class Util {
.map((rbgValue) => double.parse(rbgValue.trim())) .map((rbgValue) => double.parse(rbgValue.trim()))
.toList(); .toList();
var rgbaValues = hslToRgb(hlsaValues[0], hlsaValues[1], hlsaValues[2]); 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; double r, g, b;
if (s == 0) { if (s == 0) {
...@@ -396,30 +399,25 @@ class Util { ...@@ -396,30 +399,25 @@ class Util {
} else { } else {
double q = l < 0.5 ? l * (1 + s) : l + s - l * s; double q = l < 0.5 ? l * (1 + s) : l + s - l * s;
double p = 2 * l - q; double p = 2 * l - q;
r = hueToRgb(p, q, h + 1/3); r = hueToRgb(p, q, h + 1 / 3);
g = hueToRgb(p, q, h); 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)]; var rgb = [to255(r), to255(g), to255(b)];
return rgb; return rgb;
} }
static num to255(double v) { static num to255(double v) {
return min(255, 256*v); return min(255, 256 * v);
} }
/// Helper method that converts hue to rgb /// Helper method that converts hue to rgb
static double hueToRgb(double p, double q, double t) { static double hueToRgb(double p, double q, double t) {
if (t < 0) if (t < 0) t += 1;
t += 1; if (t > 1) t -= 1;
if (t > 1) if (t < 1 / 6) return p + (q - p) * 6 * t;
t -= 1; if (t < 1 / 2) return q;
if (t < 1/6) if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 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; return p;
} }
} }
\ No newline at end of file
...@@ -54,7 +54,7 @@ class Storage { ...@@ -54,7 +54,7 @@ class Storage {
Future<void> setItem({@required String key, @required dynamic value}) async { Future<void> setItem({@required String key, @required dynamic value}) async {
var encodedValue = json.encode(value); var encodedValue = json.encode(value);
await _controller.evaluateJavascript(source: """ 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 { ...@@ -81,10 +81,10 @@ class Storage {
} }
Future<List<WebStorageItem>> getItems() async { Future<List<WebStorageItem>> getItems() async {
var webStorageItems = <WebStorageItem>[]; var webStorageItems = <WebStorageItem>[];
List<Map<dynamic, dynamic>> items = (await _controller.evaluateJavascript(source: """ List<Map<dynamic, dynamic>> items =
(await _controller.evaluateJavascript(source: """
(function() { (function() {
var webStorageItems = []; var webStorageItems = [];
for(var i = 0; i < window.$webStorageType.length; i++){ for(var i = 0; i < window.$webStorageType.length; i++){
...@@ -105,9 +105,8 @@ class Storage { ...@@ -105,9 +105,8 @@ class Storage {
} }
for (var item in items) { for (var item in items) {
webStorageItems.add( webStorageItems
WebStorageItem(key: item["key"], value: item["value"]) .add(WebStorageItem(key: item["key"], value: item["value"]));
);
} }
return webStorageItems; return webStorageItems;
...@@ -128,9 +127,11 @@ class Storage { ...@@ -128,9 +127,11 @@ class Storage {
} }
class LocalStorage extends 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 { 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 ...@@ -838,7 +838,8 @@ class IOSInAppWebViewOptions
this.isPagingEnabled = false, this.isPagingEnabled = false,
this.maximumZoomScale = 1.0, this.maximumZoomScale = 1.0,
this.minimumZoomScale = 1.0, this.minimumZoomScale = 1.0,
this.contentInsetAdjustmentBehavior = IOSUIScrollViewContentInsetAdjustmentBehavior.NEVER}); this.contentInsetAdjustmentBehavior =
IOSUIScrollViewContentInsetAdjustmentBehavior.NEVER});
@override @override
Map<String, dynamic> toMap() { 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