Skip to content

Commit

Permalink
Add missing function
Browse files Browse the repository at this point in the history
  • Loading branch information
dnys1 committed Mar 7, 2024
1 parent 13b22eb commit af2886d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/celest_core/ffigen.glib.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ functions:
- g_hash_table_destroy
- g_application_get_default
- g_application_get_application_id
- g_error_free
structs:
include:
- _GError
Expand Down
14 changes: 14 additions & 0 deletions packages/celest_core/lib/src/native/linux/glib.ffi.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:io';

import 'package:celest_core/src/native/linux/glib.ffi.dart';
import 'package:celest_core/src/native/linux/libsecret.ffi.dart';
import 'package:celest_core/src/secure_storage/secure_storage_exception.dart';
import 'package:celest_core/src/secure_storage/secure_storage_platform.vm.dart';
import 'package:ffi/ffi.dart';

Expand Down Expand Up @@ -65,38 +66,59 @@ final class SecureStoragePlatformLinux extends SecureStoragePlatform {
void clear() => using((arena) {
final schema = _schemaFor(arena);
final attributes = _attributes(arena: arena);
final err = arena<Pointer<GError>>();
_libSecret.secret_password_clearv_sync(
schema,
attributes,
nullptr,
nullptr,
);
final error = err.value;
if (error != nullptr) {
arena.onReleaseAll(() => _glib.g_error_free(error));
final message = error.ref.message.cast<Utf8>().toDartString();
throw SecureStorageUnknownException(message);
}
});

@override
String? delete(String key) => using((arena) {
final secret = read(key);
final schema = _schemaFor(arena);
final attributes = _attributes(key: key, arena: arena);
final err = arena<Pointer<GError>>();
_libSecret.secret_password_clearv_sync(
schema,
attributes,
nullptr,
nullptr,
);
final error = err.value;
if (error != nullptr) {
arena.onReleaseAll(() => _glib.g_error_free(error));
final message = error.ref.message.cast<Utf8>().toDartString();
throw SecureStorageUnknownException(message);
}
return secret;
});

@override
String? read(String key) => using((arena) {
final attributes = _attributes(key: key, arena: arena);
final schema = _schemaFor(arena);
final err = arena<Pointer<GError>>();
final result = _libSecret.secret_password_lookupv_sync(
schema,
attributes,
nullptr,
nullptr,
err,
);
final error = err.value;
if (error != nullptr) {
arena.onReleaseAll(() => _glib.g_error_free(error));
final message = error.ref.message.cast<Utf8>().toDartString();
throw SecureStorageUnknownException(message);
}
if (result == nullptr) {
return null;
}
Expand All @@ -110,15 +132,22 @@ final class SecureStoragePlatformLinux extends SecureStoragePlatform {
final label = _labelFor(key).toNativeUtf8(allocator: arena);
final secret = value.toNativeUtf8(allocator: arena);
final attributes = _attributes(key: key, arena: arena);
final err = arena<Pointer<GError>>();
_libSecret.secret_password_storev_sync(
_schemaFor(arena),
attributes,
nullptr,
label,
secret,
nullptr,
nullptr,
err,
);
final error = err.value;
if (error != nullptr) {
arena.onReleaseAll(() => _glib.g_error_free(error));
final message = error.ref.message.cast<Utf8>().toDartString();
throw SecureStorageUnknownException(message);
}
});
return value;
}
Expand Down

0 comments on commit af2886d

Please sign in to comment.