ia64/xen-unstable

view tools/vtpm_manager/util/buffer.h @ 6946:e703abaf6e3d

Add behaviour to the remove methods to remove the transaction's path itself. This allows us to write Remove(path) to remove the specified path rather than having to slice the path ourselves.
author emellor@ewan
date Sun Sep 18 14:42:13 2005 +0100 (2005-09-18)
parents 3233e7ecfa9f
children 06d84bf87159
line source
1 // ===================================================================
2 //
3 // Copyright (c) 2005, Intel Corp.
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions
8 // are met:
9 //
10 // * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 // * Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following
14 // disclaimer in the documentation and/or other materials provided
15 // with the distribution.
16 // * Neither the name of Intel Corporation nor the names of its
17 // contributors may be used to endorse or promote products derived
18 // from this software without specific prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31 // OF THE POSSIBILITY OF SUCH DAMAGE.
32 // ===================================================================
34 #ifndef __VTPM_BUFFER_H__
35 #define __VTPM_BUFFER_H__
37 #include <stddef.h> // for pointer NULL
38 #include "tcg.h"
40 // structure to enable use of FMT_SIZE32_DATA in BSG_Unpack
41 typedef struct pack_buf_t {
42 UINT32 size;
43 BYTE * data;
44 } pack_buf_t;
46 // and a const version for Pack
47 typedef struct pack_constbuf_t {
48 UINT32 size;
49 const BYTE* data;
50 } pack_constbuf_t;
52 typedef UINT32 tpm_size_t;
54 // first version, probably will be expanded...
56 #define NULL_BUF {0,0,0,0}
58 typedef struct {
59 // private!!
60 tpm_size_t size, alloc_size;
61 BYTE * bytes;
63 BOOL is_owner; // do we own this buffer, and need to free it?
64 } buffer_t;
66 // allocate the buffer if initsize > 0, copying over initval if provided
67 TPM_RESULT buffer_init (buffer_t * buf,
68 tpm_size_t initsize,
69 const BYTE* initval);
71 // Create a new buffer from a BYTE *. Use buffer_free to destroy original BYTE *
72 TPM_RESULT buffer_init_convert (buffer_t * buf,
73 tpm_size_t initsize,
74 BYTE* initval);
76 // make an alias to a constant array, no copying
77 TPM_RESULT buffer_init_const (buffer_t * buf, tpm_size_t size, const BYTE* val);
79 // make an alias into buf, with given offset and length
80 // if len = 0, make the alias go to the end of buf
81 TPM_RESULT buffer_init_alias (buffer_t * buf, const buffer_t * b,
82 tpm_size_t offset, tpm_size_t);
84 // "copy constructor"
85 TPM_RESULT buffer_init_copy (buffer_t * buf, const buffer_t * src);
88 // copy into the start of a
89 TPM_RESULT buffer_copy (buffer_t * dest, const buffer_t* src);
91 // are they equal?
92 BOOL buffer_eq (const buffer_t * a, const buffer_t * b);
94 // set the buffer to a constant byte
95 void buffer_memset (buffer_t * buf, BYTE b);
97 tpm_size_t buffer_len (const buffer_t* buf);
99 TPM_RESULT buffer_free (buffer_t * buf);
101 TPM_RESULT buffer_append_raw (buffer_t * buf, tpm_size_t len, const BYTE* bytes);
103 #endif // _TOOLS_H_