Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Ada wrapper for Secret Service
Secret Service API
The Secret Service API is a service developped for the Gnome keyring and the KDE KWallet. It allows application to access and manage stored passwords and secrets in the two desktop environments. The libsecret is the C library that gives access to the secret service. The Secret package provides an Ada binding for this secret service API.
A secret value is represented by the Secret_Type type. The value is internally held and managed by the libsecret in some secure memory region. The secret value is associated with a content type that can be retrieved as well. The Ada library only creates secret values with the "text/plain" content type.
A secret value is only copied by reference that is the secret value stored in the secure memory region is shared among different Secret_Type instances. A secret value cannot be modified once it is created.
To create a secret value, you can use the Create function as follows:
Value : Secret.Values.Secret_Type := Secret.Values.Create ("my-secret-password");
The secret attributes describes the key/value pairs that allows the secret service to identify and retrieve a given secret value. The secret attributes are displayed by the keyring manager to the user in the "technical details" section.
The Secret.Attributes package defines the Map type for the representation of attributes and it provides operations to populate the attributes.
The Map instances use reference counting and they can be shared.
The Secret.Services package defines the Service_Type that gives access to the secret service provided by the desktop keyring manager. The service instance is declared as follows:
Service : Secret.Services.Service_Type;
The initialization is optional since the libsecret API will do the initialization itself if necessary. However, the initialization could be useful to indicate to open a session and/or to load the collections. In that case, the Initialize procedure is called:
Service.Initialize (Open_Session => True);
The list of attributes that allows to retrieve the secret value must be declared and initialized with the key/value pairs:
Attr : Secret.Attributes.Map;
and the key/value pairs are inserted as follows:
Attr.Insert ("my-key", "my-value");
The secret value is represented by the Secret_Type and it is initialized as follows:
Value : Secret.Values.Secret_Type := Secret.Values.Create ("my-password-to-protect");
Then, storing the secret value is done by the Store procedure and the label is given to help identifying the value from the keyring manager:
Service.Store (Attr, "Application password", Value);
Generated by Dynamo from secret.ads