-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sign: Factor out logic to read key blobs
This defines a new interface OstreeBlobReader, which encapsulates the key file parsing logic. This would make it easy to support custom file formats such as PEM. Signed-off-by: Daiki Ueno <[email protected]>
- Loading branch information
Showing
15 changed files
with
462 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright (C) 2024 Red Hat, Inc. | ||
* | ||
* SPDX-License-Identifier: LGPL-2.0+ | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "config.h" | ||
|
||
#include "ostree-blob-reader-base64.h" | ||
|
||
struct _OstreeBlobReaderBase64 | ||
{ | ||
GDataInputStream parent_instance; | ||
}; | ||
|
||
static void ostree_blob_reader_base64_iface_init (OstreeBlobReaderInterface *iface); | ||
|
||
G_DEFINE_TYPE_WITH_CODE (OstreeBlobReaderBase64, _ostree_blob_reader_base64, | ||
G_TYPE_DATA_INPUT_STREAM, | ||
G_IMPLEMENT_INTERFACE (OSTREE_TYPE_BLOB_READER, | ||
ostree_blob_reader_base64_iface_init)); | ||
|
||
static void | ||
ostree_blob_reader_base64_iface_init (OstreeBlobReaderInterface *iface) | ||
{ | ||
iface->read_blob = ostree_blob_reader_base64_read_blob; | ||
} | ||
|
||
static void | ||
_ostree_blob_reader_base64_class_init (OstreeBlobReaderBase64Class *klass) | ||
{ | ||
} | ||
|
||
static void | ||
_ostree_blob_reader_base64_init (OstreeBlobReaderBase64 *self) | ||
{ | ||
} | ||
|
||
OstreeBlobReaderBase64 * | ||
_ostree_blob_reader_base64_new (GInputStream *stream) | ||
{ | ||
return g_object_new (OSTREE_TYPE_BLOB_READER_BASE64, "base-stream", stream, NULL); | ||
} | ||
|
||
GBytes * | ||
ostree_blob_reader_base64_read_blob (OstreeBlobReader *self, GCancellable *cancellable, | ||
GError **error) | ||
{ | ||
gsize len = 0; | ||
g_autoptr (GError) local_error = NULL; | ||
g_autofree char *line | ||
= g_data_input_stream_read_line (G_DATA_INPUT_STREAM (self), &len, cancellable, &local_error); | ||
if (local_error != NULL) | ||
{ | ||
g_propagate_error (error, g_steal_pointer (&local_error)); | ||
return NULL; | ||
} | ||
|
||
if (line == NULL) | ||
return NULL; | ||
|
||
gsize n_elements; | ||
g_base64_decode_inplace (line, &n_elements); | ||
explicit_bzero (line + n_elements, len - n_elements); | ||
|
||
return g_bytes_new_take (g_steal_pointer (&line), n_elements); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (C) 2024 Red Hat, Inc. | ||
* | ||
* SPDX-License-Identifier: LGPL-2.0+ | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "ostree-blob-reader.h" | ||
|
||
G_BEGIN_DECLS | ||
|
||
#define OSTREE_TYPE_BLOB_READER_BASE64 (_ostree_blob_reader_base64_get_type ()) | ||
|
||
_OSTREE_PUBLIC | ||
G_DECLARE_FINAL_TYPE (OstreeBlobReaderBase64, _ostree_blob_reader_base64, OSTREE, | ||
BLOB_READER_BASE64, GDataInputStream); | ||
|
||
_OSTREE_PUBLIC | ||
OstreeBlobReaderBase64 *_ostree_blob_reader_base64_new (GInputStream *stream); | ||
|
||
_OSTREE_PUBLIC | ||
GBytes *ostree_blob_reader_base64_read_blob (OstreeBlobReader *self, GCancellable *cancellable, | ||
GError **error); | ||
|
||
G_END_DECLS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright (C) 2024 Red Hat, Inc. | ||
* | ||
* SPDX-License-Identifier: LGPL-2.0+ | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "config.h" | ||
|
||
#include "ostree-blob-reader-raw.h" | ||
|
||
struct _OstreeBlobReaderRaw | ||
{ | ||
GDataInputStream parent_instance; | ||
}; | ||
|
||
static void ostree_blob_reader_raw_iface_init (OstreeBlobReaderInterface *iface); | ||
|
||
G_DEFINE_TYPE_WITH_CODE (OstreeBlobReaderRaw, _ostree_blob_reader_raw, G_TYPE_DATA_INPUT_STREAM, | ||
G_IMPLEMENT_INTERFACE (OSTREE_TYPE_BLOB_READER, | ||
ostree_blob_reader_raw_iface_init)); | ||
|
||
static void | ||
ostree_blob_reader_raw_iface_init (OstreeBlobReaderInterface *iface) | ||
{ | ||
iface->read_blob = ostree_blob_reader_raw_read_blob; | ||
} | ||
|
||
static void | ||
_ostree_blob_reader_raw_class_init (OstreeBlobReaderRawClass *klass) | ||
{ | ||
} | ||
|
||
static void | ||
_ostree_blob_reader_raw_init (OstreeBlobReaderRaw *self) | ||
{ | ||
} | ||
|
||
OstreeBlobReaderRaw * | ||
_ostree_blob_reader_raw_new (GInputStream *stream) | ||
{ | ||
return g_object_new (OSTREE_TYPE_BLOB_READER_RAW, "base-stream", stream, NULL); | ||
} | ||
|
||
GBytes * | ||
ostree_blob_reader_raw_read_blob (OstreeBlobReader *self, GCancellable *cancellable, GError **error) | ||
{ | ||
gsize len = 0; | ||
g_autoptr (GError) local_error = NULL; | ||
g_autofree char *line | ||
= g_data_input_stream_read_line (G_DATA_INPUT_STREAM (self), &len, cancellable, &local_error); | ||
if (local_error != NULL) | ||
{ | ||
g_propagate_error (error, g_steal_pointer (&local_error)); | ||
return NULL; | ||
} | ||
|
||
if (line == NULL) | ||
return NULL; | ||
|
||
return g_bytes_new_take (g_steal_pointer (&line), len); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (C) 2024 Red Hat, Inc. | ||
* | ||
* SPDX-License-Identifier: LGPL-2.0+ | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "ostree-blob-reader.h" | ||
|
||
G_BEGIN_DECLS | ||
|
||
#define OSTREE_TYPE_BLOB_READER_RAW (_ostree_blob_reader_raw_get_type ()) | ||
|
||
_OSTREE_PUBLIC | ||
G_DECLARE_FINAL_TYPE (OstreeBlobReaderRaw, _ostree_blob_reader_raw, OSTREE, BLOB_READER_RAW, | ||
GDataInputStream); | ||
|
||
_OSTREE_PUBLIC | ||
OstreeBlobReaderRaw *_ostree_blob_reader_raw_new (GInputStream *stream); | ||
|
||
_OSTREE_PUBLIC | ||
GBytes *ostree_blob_reader_raw_read_blob (OstreeBlobReader *self, GCancellable *cancellable, | ||
GError **error); | ||
|
||
G_END_DECLS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (C) 2024 Red Hat, Inc. | ||
* | ||
* SPDX-License-Identifier: LGPL-2.0+ | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "config.h" | ||
|
||
#include "ostree-blob-reader.h" | ||
|
||
G_DEFINE_INTERFACE (OstreeBlobReader, ostree_blob_reader, G_TYPE_OBJECT); | ||
|
||
static void | ||
ostree_blob_reader_default_init (OstreeBlobReaderInterface *iface) | ||
{ | ||
g_debug ("OstreeBlobReader initialization"); | ||
} | ||
|
||
GBytes * | ||
ostree_blob_reader_read_blob (OstreeBlobReader *self, GCancellable *cancellable, GError **error) | ||
{ | ||
g_assert (OSTREE_IS_BLOB_READER (self)); | ||
return OSTREE_BLOB_READER_GET_IFACE (self)->read_blob (self, cancellable, error); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (C) 2024 Red Hat, Inc. | ||
* | ||
* SPDX-License-Identifier: LGPL-2.0+ | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "ostree-types.h" | ||
#include <gio/gio.h> | ||
|
||
G_BEGIN_DECLS | ||
|
||
#define OSTREE_TYPE_BLOB_READER (ostree_blob_reader_get_type ()) | ||
_OSTREE_PUBLIC | ||
G_DECLARE_INTERFACE (OstreeBlobReader, ostree_blob_reader, OSTREE, BLOB_READER, GObject) | ||
|
||
struct _OstreeBlobReaderInterface | ||
{ | ||
GTypeInterface g_iface; | ||
|
||
GBytes *(*read_blob) (OstreeBlobReader *self, GCancellable *cancellable, GError **error); | ||
}; | ||
|
||
_OSTREE_PUBLIC | ||
GBytes *ostree_blob_reader_read_blob (OstreeBlobReader *self, GCancellable *cancellable, | ||
GError **error); | ||
|
||
G_END_DECLS |
Oops, something went wrong.