Skip to content

Commit

Permalink
uprgraded some libraries and kotlin version
Browse files Browse the repository at this point in the history
  • Loading branch information
nejc-skerjanc committed Oct 2, 2023
1 parent b254d1c commit 175febc
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 5 deletions.
4 changes: 2 additions & 2 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 32
compileSdkVersion 33

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand All @@ -40,7 +40,7 @@ android {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.mrtdeg"
minSdkVersion 21
targetSdkVersion 32
targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
5 changes: 3 additions & 2 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
buildscript {
ext.kotlin_version = '1.6.10'
//ext.kotlin_version = '1.6.21'
ext.kotlin_version = '1.8.0'
repositories {
google()
jcenter()
Expand All @@ -26,6 +27,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
Empty file added lib/src/constants/asn1_ber.dart
Empty file.
103 changes: 103 additions & 0 deletions lib/src/lds/asn1ObjectIdentifiers.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Created by Nejc Skerjanc, copyright © 2023 ZeroPass. All rights reserved.

import 'dart:typed_data';
import 'package:dmrtd/extensions.dart';
import 'package:logging/logging.dart';
import 'package:pointycastle/asn1.dart';
import 'package:pointycastle/asn1/object_identifiers_database.dart';

import '../../types/exception.dart';


// here you can add additional object identifiers that are not defined in pointycastle library
List<Map<String, Object>> customOIDS = [
{
'identifierString': '1.2.3.4.5', 'readableName': 'someName', 'identifier': [0, 1, 2, 3, 4, 5]
}
];


// add additional object identifiers

class ASN1ObjectIdentifierException implements DMRTDException {
final String message;
@override
String exceptionName = 'ASN1ObjectIdentifierException';

ASN1ObjectIdentifierException(this.message);
//@override
//String toString() {
// String result = 'ASN1ObjectIdentifierException';
// if (message is String) return '$result: $message';
// return result;
//}


}


class ASN1ObjectIdentifiers {
// object identifiers that are defined in pointycastle library
List<Map<String, Object>> _OIDS = oi;
final _log = Logger("ASN1ObjectIdentifiers");


ASN1ObjectIdentifiers(){
// add custom object identifiers to existing ones
for (var customOID in customOIDS) {
if (!checkOID(item:customOID)){
throw ASN1ObjectIdentifierException('Object identifier is not valid.');
}
_OIDS.add(customOID);
}
}

// check if object identifier is valid
bool checkOID({required Map<String, Object> item}){
//check if list contains all required keys
if (!item.containsKey('identifier') || !item.containsKey('identifierString') || !item.containsKey('readableName')) {
_log.error('Object identifier must contain identifier, identifierString and readableName.');
return false;
}

if (item['identifier'] is! List<int>) {
_log.error('Object identifier identifier must be List<int>.');
return false;
}
if (item['identifierString'] is! String) {
_log.error('Object identifier identifierString must be String.');
return false;
}
if (item['readableName'] is! String) {
_log.error('Object identifier readableName must be String.');
return false;
}
return true;
}


// has object identifier with identifier string
bool hasOIDWithIdentifierString(String identifierString) {
return _OIDS.any((element) => element['identifierString'] == identifierString);
}


// get object identifier by identifier string
Map<String, Object> getOIDByIdentifierString(String identifierString) {
return _OIDS.firstWhere((element) => element['identifierString'] == identifierString, orElse: () =>
throw ASN1ObjectIdentifierException('Object identifier with identifier string $identifierString does not exist.'));
}

// has object identifier wih identifier
bool hasOIDWithIdentifier(List<int> identifier) {
return _OIDS.any((element) => element['identifier'] == identifier);
}

// get object identifier by identifier
Map<String, Object> getOIDByIdentifier(List<int> identifier) {
return _OIDS.firstWhere((element) => element['identifier'] == identifier, orElse: () =>
throw ASN1ObjectIdentifierException('Object identifier with identifier $identifier does not exist.'));
}

}

Empty file.
Empty file added lib/src/types/exception.dart
Empty file.
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ dependencies:
crypto: ^3.0.1
expandable: ^5.0.1
fixnum: ^1.0.0
flutter_nfc_kit: '^3.1.0'
flutter_nfc_kit: ^3.3.1
logging: ^1.0.1
meta: ^1.3.0
tripledes_nullsafety: ^1.0.3
pointycastle: ^3.7.3

dev_dependencies:
flutter: # needed for flutter_nfc_kit
Expand Down

0 comments on commit 175febc

Please sign in to comment.