Skip to content

Commit 1e49b3d

Browse files
committed
Fechamento classe AskarKeyEntryList
1 parent c5e69ea commit 1e49b3d

File tree

4 files changed

+90
-34
lines changed

4 files changed

+90
-34
lines changed

lib/exceptions/askar_exceptions/exceptions.dart

+12
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,15 @@ class AskarStoreException implements Exception {
3333
return "Exception: $message";
3434
}
3535
}
36+
37+
class AskarKeyEntryListException implements Exception {
38+
final String? message;
39+
40+
AskarKeyEntryListException([this.message]);
41+
42+
@override
43+
String toString() {
44+
if (message == null) return "Exception";
45+
return "Exception: $message";
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,90 @@
1+
import '../../askar/askar_wrapper.dart';
2+
import '../../askar/enums/askar_error_code.dart';
3+
import '../../exceptions/askar_exceptions/exceptions.dart';
14
import 'askar_key_entry_list_interface.dart';
25

36
class AskarKeyEntryList implements IAskarKeyEntryList {
47
//KeyEntryListHandle é necessário
58
//Valor é obtido em AskarSession.fetchKeys ou AskarSession.fetchAllKeys
9+
final KeyEntryListHandle? handle;
10+
11+
AskarKeyEntryList({required this.handle});
612

713
@override
8-
Future<bool> count() {
9-
// TODO: implement count
10-
throw UnimplementedError();
14+
int count() {
15+
checkHandle();
16+
final response = askarKeyEntryListCount(handle!);
17+
if (response.errorCode == ErrorCode.success) {
18+
return response.value;
19+
}
20+
throw AskarKeyEntryListException(
21+
"Erro ao contar entradas de chave - Verificar HANDLE");
1122
}
1223

1324
@override
14-
Future<bool> free() {
15-
// TODO: implement free
16-
throw UnimplementedError();
25+
void free() {
26+
checkHandle();
27+
askarKeyEntryListFree(handle!);
1728
}
1829

1930
@override
20-
Future<bool> getAlgorithm() {
21-
// TODO: implement getAlgorithm
22-
throw UnimplementedError();
31+
String getAlgorithm(int index) {
32+
checkHandle();
33+
final response = askarKeyEntryListGetAlgorithm(handle!, index);
34+
if (response.errorCode == ErrorCode.success) {
35+
return response.value;
36+
}
37+
throw AskarKeyEntryListException(
38+
"Erro ao contar entradas de chave - Verificar HANDLE");
2339
}
2440

2541
@override
26-
Future<bool> getMetadata() {
27-
// TODO: implement getMetadata
28-
throw UnimplementedError();
42+
String getMetadata(int index) {
43+
checkHandle();
44+
final response = askarKeyEntryListGetMetadata(handle!, index);
45+
if (response.errorCode == ErrorCode.success) {
46+
return response.value;
47+
}
48+
throw AskarKeyEntryListException(
49+
"Erro ao contar entradas de chave - Verificar HANDLE");
2950
}
3051

3152
@override
32-
Future<bool> getName() {
33-
// TODO: implement getName
34-
throw UnimplementedError();
53+
String getName(int index) {
54+
checkHandle();
55+
final response = askarKeyEntryListGetName(handle!, index);
56+
if (response.errorCode == ErrorCode.success) {
57+
return response.value;
58+
}
59+
throw AskarKeyEntryListException(
60+
"Erro ao contar entradas de chave - Verificar HANDLE");
3561
}
3662

3763
@override
38-
Future<bool> getTags() {
39-
// TODO: implement getTags
40-
throw UnimplementedError();
64+
Map getTags(int index) {
65+
checkHandle();
66+
final response = askarKeyEntryListGetTags(handle!, index);
67+
if (response.errorCode == ErrorCode.success) {
68+
return response.value;
69+
}
70+
throw AskarKeyEntryListException(
71+
"Erro ao contar entradas de chave - Verificar HANDLE");
4172
}
4273

4374
@override
44-
Future<bool> loadLocal() {
45-
// TODO: implement loadLocal
46-
throw UnimplementedError();
75+
LocalKeyHandle loadLocal(int index) {
76+
checkHandle();
77+
final response = askarKeyEntryListLoadLocal(handle!, index);
78+
if (response.errorCode == ErrorCode.success) {
79+
return response.value;
80+
}
81+
throw AskarKeyEntryListException(
82+
"Erro ao contar entradas de chave - Verificar HANDLE");
83+
}
84+
85+
checkHandle() {
86+
if (handle == null) {
87+
throw AskarKeyEntryListException("KeyEntryListHandle não iniciado");
88+
}
4789
}
4890
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import '../../askar/askar_wrapper.dart';
2+
13
abstract class IAskarKeyEntryList {
2-
Future<bool> count();
3-
Future<bool> free();
4-
Future<bool> getAlgorithm();
5-
Future<bool> getMetadata();
6-
Future<bool> getName();
7-
Future<bool> getTags();
8-
Future<bool> loadLocal();
4+
int count();
5+
void free();
6+
String getAlgorithm(int index);
7+
String getMetadata(int index);
8+
String getName(int index);
9+
Map getTags(int index);
10+
LocalKeyHandle loadLocal(int index);
911
}

lib/models/askar_session/askar_session.dart

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ class AskarSession implements IAskarSession {
2828
return false;
2929
}
3030

31-
checkSession() {
32-
if (handle == null) {
33-
throw AskarSessionException("Sessão não iniciada");
34-
}
35-
}
36-
3731
@override
3832
Future<bool> close({required bool commit}) async {
3933
checkSession();
@@ -152,4 +146,10 @@ class AskarSession implements IAskarSession {
152146
}
153147
return false;
154148
}
149+
150+
checkSession() {
151+
if (handle == null) {
152+
throw AskarSessionException("Sessão não iniciada");
153+
}
154+
}
155155
}

0 commit comments

Comments
 (0)