ia64/xen-unstable

view tools/vtpm_manager/util/buffer.h @ 8740:3d7ea7972b39

Update patches for linux 2.6.15.

Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Thu Feb 02 17:16:00 2006 +0000 (2006-02-02)
parents 89030fab2c3f
children 5014fd2b5c5a
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 typedef UINT32 tpm_size_t;
42 // first version, probably will be expanded...
44 #define NULL_BUF {0,0,0,0}
46 typedef struct {
47 // private!!
48 tpm_size_t size, alloc_size;
49 BYTE * bytes;
51 BOOL is_owner; // do we own this buffer, and need to free it?
52 } buffer_t;
54 // allocate the buffer if initsize > 0, copying over initval if provided
55 TPM_RESULT buffer_init (buffer_t * buf,
56 tpm_size_t initsize,
57 const BYTE* initval);
59 // Create a new buffer from a BYTE *. Use buffer_free to destroy original BYTE *
60 TPM_RESULT buffer_init_convert (buffer_t * buf,
61 tpm_size_t initsize,
62 BYTE* initval);
64 // make an alias to a constant array, no copying
65 TPM_RESULT buffer_init_const (buffer_t * buf, tpm_size_t size, const BYTE* val);
67 // make an alias into buf, with given offset and length
68 // if len = 0, make the alias go to the end of buf
69 TPM_RESULT buffer_init_alias (buffer_t * buf, const buffer_t * b,
70 tpm_size_t offset, tpm_size_t);
72 // "copy constructor"
73 TPM_RESULT buffer_init_copy (buffer_t * buf, const buffer_t * src);
76 // copy into the start of a
77 TPM_RESULT buffer_copy (buffer_t * dest, const buffer_t* src);
79 // are they equal?
80 BOOL buffer_eq (const buffer_t * a, const buffer_t * b);
82 // set the buffer to a constant byte
83 void buffer_memset (buffer_t * buf, BYTE b);
85 tpm_size_t buffer_len (const buffer_t* buf);
87 TPM_RESULT buffer_free (buffer_t * buf);
89 TPM_RESULT buffer_append_raw (buffer_t * buf, tpm_size_t len, const BYTE* bytes);
91 #endif // _TOOLS_H_