mirror of
https://github.com/xtool-org/xtool.git
synced 2026-11-16 04:25:00 +03:00
more cleanup
This commit is contained in:
@@ -20,15 +20,12 @@ typedef struct mobileprovision *mobileprovision_t;
|
||||
/// create a profile from the given data
|
||||
_Nullable mobileprovision_t mobileprovision_create_from_data(const void *data, size_t len);
|
||||
|
||||
/// create a profile from the given file path
|
||||
_Nullable mobileprovision_t mobileprovision_create_from_path(const char *path);
|
||||
|
||||
/// free `profile`
|
||||
void mobileprovision_free(mobileprovision_t profile);
|
||||
|
||||
// MARK: - Operations
|
||||
|
||||
void * _Nullable mobileprovision_get_data(mobileprovision_t profile, size_t *len);
|
||||
void * _Nullable mobileprovision_copy_data(mobileprovision_t profile, size_t *len);
|
||||
|
||||
const void * _Nullable mobileprovision_get_digest(mobileprovision_t profile, size_t *len);
|
||||
|
||||
|
||||
@@ -30,24 +30,12 @@ mobileprovision_t mobileprovision_create_from_data(const void *data, size_t len)
|
||||
return mobileprovision_create(raw);
|
||||
}
|
||||
|
||||
mobileprovision_t mobileprovision_create_from_path(const char *path) {
|
||||
BIO *file = BIO_new_file(path, "r");
|
||||
if (!file) return NULL;
|
||||
|
||||
PKCS7 *raw = NULL;
|
||||
d2i_PKCS7_bio(file, &raw);
|
||||
|
||||
BIO_free(file);
|
||||
|
||||
return mobileprovision_create(raw);
|
||||
}
|
||||
|
||||
void mobileprovision_free(mobileprovision_t profile) {
|
||||
PKCS7_free(profile->raw);
|
||||
free(profile);
|
||||
}
|
||||
|
||||
void *mobileprovision_get_data(mobileprovision_t profile, size_t *len) {
|
||||
void *mobileprovision_copy_data(mobileprovision_t profile, size_t *len) {
|
||||
unsigned char *data = NULL;
|
||||
size_t data_len = i2d_PKCS7(profile->raw, &data);
|
||||
if (data_len < 0) return NULL;
|
||||
|
||||
@@ -53,12 +53,6 @@ public final class Mobileprovision: Decodable {
|
||||
self.raw = profile
|
||||
}
|
||||
|
||||
public init(contentsOf url: URL) throws {
|
||||
guard let profile = url.withUnsafeFileSystemRepresentation({ $0.flatMap(mobileprovision_create_from_path) })
|
||||
else { throw Error.invalidProfile }
|
||||
self.raw = profile
|
||||
}
|
||||
|
||||
public required init(from decoder: Decoder) throws {
|
||||
let container = try decoder.singleValueContainer()
|
||||
let data = try container.decode(Data.self)
|
||||
@@ -86,7 +80,7 @@ public final class Mobileprovision: Decodable {
|
||||
}
|
||||
|
||||
public func data() throws -> Data {
|
||||
try Data { mobileprovision_get_data(raw, &$0) }.orThrow(Error.invalidProfile)
|
||||
try Data { mobileprovision_copy_data(raw, &$0) }.orThrow(Error.invalidProfile)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user