|
| 1 | +import '../../askar/askar_wrapper.dart'; |
| 2 | +import '../../askar/enums/askar_error_code.dart'; |
| 3 | +import '../../exceptions/askar_exceptions/exceptions.dart'; |
1 | 4 | import 'askar_key_entry_list_interface.dart';
|
2 | 5 |
|
3 | 6 | class AskarKeyEntryList implements IAskarKeyEntryList {
|
4 | 7 | //KeyEntryListHandle é necessário
|
5 | 8 | //Valor é obtido em AskarSession.fetchKeys ou AskarSession.fetchAllKeys
|
| 9 | + final KeyEntryListHandle? handle; |
| 10 | + |
| 11 | + AskarKeyEntryList({required this.handle}); |
6 | 12 |
|
7 | 13 | @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"); |
11 | 22 | }
|
12 | 23 |
|
13 | 24 | @override
|
14 |
| - Future<bool> free() { |
15 |
| - // TODO: implement free |
16 |
| - throw UnimplementedError(); |
| 25 | + void free() { |
| 26 | + checkHandle(); |
| 27 | + askarKeyEntryListFree(handle!); |
17 | 28 | }
|
18 | 29 |
|
19 | 30 | @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"); |
23 | 39 | }
|
24 | 40 |
|
25 | 41 | @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"); |
29 | 50 | }
|
30 | 51 |
|
31 | 52 | @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"); |
35 | 61 | }
|
36 | 62 |
|
37 | 63 | @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"); |
41 | 72 | }
|
42 | 73 |
|
43 | 74 | @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 | + } |
47 | 89 | }
|
48 | 90 | }
|
0 commit comments