Gcr.Parser¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
|
|
|
Properties¶
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r |
Parsed PKCS#11 attributes |
||
r |
Parsed item description |
||
r |
Parsed item label |
Signals¶
- Inherited:
Name |
Short Description |
---|---|
This signal is emitted when an item needs to be unlocked or decrypted before it can be parsed. |
|
This signal is emitted when an item is sucessfully parsed. |
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
---|---|---|---|
parent |
r |
Class Details¶
- class Gcr.Parser(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
A parser for parsing various types of files or data.
A
GcrParser
can parse various certificate and key files such as OpenSSL PEM files, DER encoded certifictes, PKCS#8 keys and so on. Each various format is identified by a value in the [enum`DataFormat`] enumeration.In order to parse data, a new parser is created with
Gcr.Parser.new
() and then the [signal`Parser`:py:func:::authenticate<Gcr.Parser.signals.authenticate>] and [signal`Parser`:py:func:::parsed<Gcr.Parser.signals.parsed>] signals should be connected to. Data is then fed to the parser via [method`Parser`.parse_data] or [method`Parser`.parse_stream].During the [signal`Parser`:py:func:::parsed<Gcr.Parser.signals.parsed>] signal the attributes that make up the currently parsed item can be retrieved using the [method`Parser`.get_parsed_attributes] function.
- classmethod new()[source]¶
- Returns:
a newly allocated
Gcr.Parser
- Return type:
Create a new
Gcr.Parser
- add_password(password)[source]¶
-
Add a password to the set of passwords to try when parsing locked or encrypted items. This is usually called from the [signal`Parser`:py:func:::authenticate<Gcr.Parser.signals.authenticate>] signal.
- format_disable(format)[source]¶
- Parameters:
format (
Gcr.DataFormat
) – The format identifier
Disable parsing of the given format. Use
Gcr.DataFormat.ALL
to disable all the formats.
- format_enable(format)[source]¶
- Parameters:
format (
Gcr.DataFormat
) – The format identifier
Enable parsing of the given format. Use
Gcr.DataFormat.ALL
to enable all the formats.
- format_supported(format)[source]¶
- Parameters:
format (
Gcr.DataFormat
) – The format identifier- Returns:
Whether the format is supported.
- Return type:
Check whether the given format is supported by the parser.
- get_parsed_attributes()[source]¶
- Returns:
the attributes for the current item, which are owned by the parser and should not be freed
- Return type:
Get the attributes which make up the currently parsed item. This is generally only valid during the [signal`Parser`:py:func:::parsed<Gcr.Parser.signals.parsed>] signal.
- get_parsed_block()[source]¶
- Returns:
the raw data block of the currently parsed item; the value is owned by the parser and should not be freed
- Return type:
Get the raw data block that represents this parsed object. This is only valid during the [signal`Parser`:py:func:::parsed<Gcr.Parser.signals.parsed>] signal.
- get_parsed_bytes()[source]¶
- Returns:
the raw data block of the currently parsed item
- Return type:
Get the raw data block that represents this parsed object. This is only valid during the [signal`Parser`:py:func:::parsed<Gcr.Parser.signals.parsed>] signal.
- get_parsed_description()[source]¶
- Returns:
the description for the current item; this is owned by the parser and should not be freed
- Return type:
Get a description for the type of the currently parsed item. This is generally only valid during the [signal`Parser`:py:func:::parsed<Gcr.Parser.signals.parsed>] signal.
- get_parsed_format()[source]¶
- Returns:
the data format of the currently parsed item
- Return type:
Get the format of the raw data block that represents this parsed object. This corresponds with the data returned from [method`Parser`.get_parsed_block].
This is only valid during the [signal`Parser`:py:func:::parsed<Gcr.Parser.signals.parsed>] signal.
- get_parsed_label()[source]¶
- Returns:
the label of the currently parsed item. The value is owned by the parser and should not be freed.
- Return type:
Get the label of the currently parsed item. This is generally only valid during the [signal`Parser`:py:func:::parsed<Gcr.Parser.signals.parsed>] signal.
- parse_bytes(data)[source]¶
- Parameters:
data (
GLib.Bytes
) – the data to parse- Raises:
- Returns:
Whether the data was parsed successfully or not.
- Return type:
Parse the data. The [signal`Parser`:py:func:::parsed<Gcr.Parser.signals.parsed>] and [signal`Parser`:py:func:::authenticate<Gcr.Parser.signals.authenticate>] signals may fire during the parsing.
- parse_data(data)[source]¶
- Parameters:
data (
bytes
) – the data to parse- Raises:
- Returns:
Whether the data was parsed successfully or not.
- Return type:
Parse the data. The [signal`Parser`:py:func:::parsed<Gcr.Parser.signals.parsed>] and [signal`Parser`:py:func:::authenticate<Gcr.Parser.signals.authenticate>] signals may fire during the parsing.
A copy of the data will be made. Use [method`Parser`.parse_bytes] to avoid this.
- parse_stream(input, cancellable)[source]¶
- Parameters:
input (
Gio.InputStream
) – The input streamcancellable (
Gio.Cancellable
orNone
) – An optional cancellation object
- Raises:
- Returns:
Whether the parsing completed successfully or not.
- Return type:
Parse items from the data in a
Gio.InputStream
. This function may block while reading from the input stream. Use [method`Parser`.parse_stream_async] for a non-blocking variant.The [signal`Parser`:py:func:::parsed<Gcr.Parser.signals.parsed>] and [signal`Parser`:py:func:::authenticate<Gcr.Parser.signals.authenticate>] signals may fire during the parsing.
- parse_stream_async(input, cancellable, callback, *user_data)[source]¶
- Parameters:
input (
Gio.InputStream
) – The input streamcancellable (
Gio.Cancellable
orNone
) – An optional cancellation objectcallback (
Gio.AsyncReadyCallback
orNone
) – Called when the operation result is ready.
Parse items from the data in a
Gio.InputStream
. This function completes asyncronously and doesn’t block.The [signal`Parser`:py:func:::parsed<Gcr.Parser.signals.parsed>] and [signal`Parser`:py:func:::authenticate<Gcr.Parser.signals.authenticate>] signals may fire during the parsing.
- parse_stream_finish(result)[source]¶
- Parameters:
result (
Gio.AsyncResult
) – The operation result- Raises:
- Returns:
Whether the parsing completed successfully or not.
- Return type:
Complete an operation to parse a stream.
- do_parsed() virtual¶
Signal Details¶
- Gcr.Parser.signals.authenticate(parser, count)¶
- Signal Name:
authenticate
- Flags:
- Parameters:
parser (
Gcr.Parser
) – The object which received the signalcount (
int
) – the number of times this item has been authenticated
- Returns:
Whether the authentication was handled.
- Return type:
This signal is emitted when an item needs to be unlocked or decrypted before it can be parsed. The count argument specifies the number of times the signal has been emitted for a given item. This can be used to display a message saying the previous password was incorrect.
Typically the
Gcr.Parser.add_password
() function is called in response to this signal.If
False
is returned, then the authentication was not handled. If no handlers returnTrue
then the item is not parsed and an error with the codeGcr.DataError.CANCELLED
will be raised.
- Gcr.Parser.signals.parsed(parser)¶
- Signal Name:
parsed
- Flags:
- Parameters:
parser (
Gcr.Parser
) – The object which received the signal
This signal is emitted when an item is sucessfully parsed. To access the information about the item use the
Gcr.Parser.get_parsed_label
(),Gcr.Parser.get_parsed_attributes
() andGcr.Parser.get_parsed_description
() functions.
Property Details¶
- Gcr.Parser.props.parsed_attributes¶
- Name:
parsed-attributes
- Type:
- Default Value:
- Flags:
Get the attributes that make up the currently parsed item. This is generally only valid during a [signal`Parser`:py:func:::parsed<Gcr.Parser.signals.parsed>] signal.
- Gcr.Parser.props.parsed_description¶
-
The description of the type of the currently parsed item. This is generally only valid during a [signal`Parser`:py:func:::parsed<Gcr.Parser.signals.parsed>] signal.