blob: 22b314150e3fa372bc348d2b899a29d0d58e5a2b [file] [log] [blame]
Randall Spanglerd55c6452010-06-10 12:43:51 -07001/* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 *
5 * Host-side misc functions for verified boot.
6 */
7
8#ifndef VBOOT_REFERENCE_HOST_MISC_H_
9#define VBOOT_REFERENCE_HOST_MISC_H_
10
Randall Spanglerd55c6452010-06-10 12:43:51 -070011#include "utility.h"
12#include "vboot_struct.h"
13
Randall Spanglereb591952011-04-07 10:02:00 -070014/* Copy up to dest_size-1 characters from src to dest, ensuring null
15 termination (which strncpy() doesn't do). Returns the destination
16 string. */
17char* StrCopy(char* dest, const char* src, int dest_size);
Randall Spanglerd55c6452010-06-10 12:43:51 -070018
19/* Read data from [filename]. Store the size of returned data in [size].
20 *
21 * Returns the data buffer, which the caller must Free(), or NULL if
22 * error. */
23uint8_t* ReadFile(const char* filename, uint64_t* size);
24
Randall Spanglereb591952011-04-07 10:02:00 -070025/* Read a string from a file. Passed the destination, dest size, and
26 * filename to read.
27 *
28 * Returns the destination, or NULL if error. */
29char* ReadFileString(char* dest, int size, const char* filename);
30
31/* Read an integer from a file.
32 *
33 * Returns the parsed integer, or -1 if error. */
34int ReadFileInt(const char* filename);
35
36/* Check if a bit is set in a file which contains an integer.
37 *
38 * Returns 1 if the bit is set, 0 if clear, or -1 if error. */
39int ReadFileBit(const char* filename, int bitmask);
Randall Spanglerd55c6452010-06-10 12:43:51 -070040
Randall Spangler6a97b3e2010-06-10 17:55:02 -070041/* Writes [size] bytes of [data] to [filename].
42 *
43 * Returns 0 if success, 1 if error. */
44int WriteFile(const char* filename, const void *data, uint64_t size);
45
Bill Richardson60bcbe32010-09-09 14:53:56 -070046/* Prints the sha1sum of the given VbPublicKey to stdout. */
47void PrintPubKeySha1Sum(VbPublicKey* key);
Randall Spangler6a97b3e2010-06-10 17:55:02 -070048
Randall Spanglerd55c6452010-06-10 12:43:51 -070049#endif /* VBOOT_REFERENCE_HOST_MISC_H_ */