mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-11-24 10:14:55 +00:00
Refactor LoadFirmware() to avoid global variables, which don't work when running out of ROM
Review URL: http://codereview.chromium.org/2848006
This commit is contained in:
@@ -33,21 +33,11 @@ VbPrivateKey* PrivateKeyRead(const char* filename, uint64_t algorithm);
|
||||
void PrivateKeyFree(VbPrivateKey* key);
|
||||
|
||||
|
||||
/* Initialize a public key to refer to [key_data]. */
|
||||
void PublicKeyInit(VbPublicKey* key, uint8_t* key_data, uint64_t key_size);
|
||||
|
||||
|
||||
/* Allocate a new public key with space for a [key_size] byte key. */
|
||||
VbPublicKey* PublicKeyAlloc(uint64_t key_size, uint64_t algorithm,
|
||||
uint64_t version);
|
||||
|
||||
|
||||
/* Copy a public key from [src] to [dest].
|
||||
*
|
||||
* Returns 0 if success, non-zero if error. */
|
||||
int PublicKeyCopy(VbPublicKey* dest, const VbPublicKey* src);
|
||||
|
||||
|
||||
/* Read a public key from a .vbpubk file. Caller owns the returned
|
||||
* pointer, and must free it with Free().
|
||||
*
|
||||
|
||||
@@ -72,14 +72,6 @@ void PrivateKeyFree(VbPrivateKey* key) {
|
||||
}
|
||||
|
||||
|
||||
void PublicKeyInit(VbPublicKey* key, uint8_t* key_data, uint64_t key_size) {
|
||||
key->key_offset = OffsetOf(key, key_data);
|
||||
key->key_size = key_size;
|
||||
key->algorithm = kNumAlgorithms; /* Key not present yet */
|
||||
key->key_version = 0;
|
||||
}
|
||||
|
||||
|
||||
/* Allocate a new public key with space for a [key_size] byte key. */
|
||||
VbPublicKey* PublicKeyAlloc(uint64_t key_size, uint64_t algorithm,
|
||||
uint64_t version) {
|
||||
@@ -95,21 +87,6 @@ VbPublicKey* PublicKeyAlloc(uint64_t key_size, uint64_t algorithm,
|
||||
}
|
||||
|
||||
|
||||
/* Copy a public key from [src] to [dest].
|
||||
*
|
||||
* Returns zero if success, non-zero if error. */
|
||||
int PublicKeyCopy(VbPublicKey* dest, const VbPublicKey* src) {
|
||||
if (dest->key_size < src->key_size)
|
||||
return 1;
|
||||
|
||||
dest->key_size = src->key_size;
|
||||
dest->algorithm = src->algorithm;
|
||||
dest->key_version = src->key_version;
|
||||
Memcpy(GetPublicKeyData(dest), GetPublicKeyDataC(src), src->key_size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
VbPublicKey* PublicKeyReadKeyb(const char* filename, uint64_t algorithm,
|
||||
uint64_t version) {
|
||||
VbPublicKey* key;
|
||||
|
||||
@@ -7,9 +7,7 @@ int main(void)
|
||||
/* host_key.h */
|
||||
PrivateKeyRead(0, 0);
|
||||
PrivateKeyFree(0);
|
||||
PublicKeyInit(0, 0, 0);
|
||||
PublicKeyAlloc(0, 0, 0);
|
||||
PublicKeyCopy(0, 0);
|
||||
PublicKeyRead(0);
|
||||
PublicKeyReadKeyb(0, 0, 0);
|
||||
PublicKeyWrite(0, 0);
|
||||
|
||||
Reference in New Issue
Block a user