# Dynamic Buffer

**API Group:** `xmlsec_core_buffer`

Dynamic binary buffer implementation.

Binary memory buffer functions.

## Enumerations

### `xmlSecAllocMode`

*Source:* [include/xmlsec/buffer.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/buffer.h#L28)

The memory allocation mode.

The memory allocation mode (used by xmlSecBuffer and xmlSecList).

| Value | Initializer | Description |
|-------|-------------|-------------|
| `xmlSecAllocModeExact` | `= 0` |  |
| `xmlSecAllocModeDouble` | `` |  |

---

## Functions

### `xmlSecBufferSetDefaultAllocMode`

```c
void xmlSecBufferSetDefaultAllocMode(xmlSecAllocMode defAllocMode, xmlSecSize defInitialSize);
```

*Source:* [include/xmlsec/buffer.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/buffer.h#L49)

Sets the default buffer allocation mode.

Sets new global default allocation mode and minimal intial size. 

**Parameters:**

- `defAllocMode` — the new default buffer allocation mode.
- `defInitialSize` — the new default buffer minimal intial size.

---

### `xmlSecBufferCreate`

```c
xmlSecBufferPtr xmlSecBufferCreate(xmlSecSize size);
```

*Source:* [include/xmlsec/buffer.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/buffer.h#L52)

Allocates and initializes a new memory buffer.

Allocates and initializes new memory buffer with given size. Caller is responsible for calling `xmlSecBufferDestroy` function to free the buffer. 

**Parameters:**

- `size` — the intial size.


**Returns:** pointer to newly allocated buffer or NULL if an error occurs.

---

### `xmlSecBufferDestroy`

```c
void xmlSecBufferDestroy(xmlSecBufferPtr buf);
```

*Source:* [include/xmlsec/buffer.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/buffer.h#L53)

Destroys a buffer object.

Destroys buffer object created with `xmlSecBufferCreate` function. 

**Parameters:**

- `buf` — the pointer to buffer object.

---

### `xmlSecBufferInitialize`

```c
int xmlSecBufferInitialize(xmlSecBufferPtr buf, xmlSecSize size);
```

*Source:* [include/xmlsec/buffer.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/buffer.h#L54)

Initializes a buffer object.

Initializes buffer object `buf`. Caller is responsible for calling `xmlSecBufferFinalize` function to free allocated resources. 

**Parameters:**

- `buf` — the pointer to buffer object.
- `size` — the initial buffer size.


**Returns:** 0 on success or a negative value if an error occurs.

---

### `xmlSecBufferFinalize`

```c
void xmlSecBufferFinalize(xmlSecBufferPtr buf);
```

*Source:* [include/xmlsec/buffer.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/buffer.h#L56)

Frees resources for an initialized buffer.

Frees allocated resource for a buffer initialized with `xmlSecBufferInitialize` function. 

**Parameters:**

- `buf` — the pointer to buffer object.

---

### `xmlSecBufferIsEmpty`

```c
int xmlSecBufferIsEmpty(xmlSecBufferPtr buf);
```

*Source:* [include/xmlsec/buffer.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/buffer.h#L57)

Checks if the buffer is empty.

Checks if the `buf` is empty (`buf` is null or `buf's` data is null or `buf's` size is zero). 

**Parameters:**

- `buf` — the pointer to buffer object.


**Returns:** 1 if buffer is empty or 0 otherwise.

---

### `xmlSecBufferGetData`

```c
xmlSecByte * xmlSecBufferGetData(xmlSecBufferPtr buf);
```

*Source:* [include/xmlsec/buffer.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/buffer.h#L58)

Gets pointer to buffer's data.

**Parameters:**

- `buf` — the pointer to buffer object.


**Returns:** pointer to buffer's data.

---

### `xmlSecBufferSetData`

```c
int xmlSecBufferSetData(xmlSecBufferPtr buf, const xmlSecByte *data, xmlSecSize size);
```

*Source:* [include/xmlsec/buffer.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/buffer.h#L59)

Sets the value of the buffer to `data`.

**Parameters:**

- `buf` — the pointer to buffer object.
- `data` — the data.
- `size` — the data size.


**Returns:** 0 on success or a negative value if an error occurs.

---

### `xmlSecBufferGetSize`

```c
xmlSecSize xmlSecBufferGetSize(xmlSecBufferPtr buf);
```

*Source:* [include/xmlsec/buffer.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/buffer.h#L62)

Gets the current buffer data size.

**Parameters:**

- `buf` — the pointer to buffer object.


**Returns:** the current data size.

---

### `xmlSecBufferSetSize`

```c
int xmlSecBufferSetSize(xmlSecBufferPtr buf, xmlSecSize size);
```

*Source:* [include/xmlsec/buffer.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/buffer.h#L63)

Sets new buffer data size.

Sets new buffer data size. If necessary, buffer grows to have at least `size` bytes. 

**Parameters:**

- `buf` — the pointer to buffer object.
- `size` — the new data size.


**Returns:** 0 on success or a negative value if an error occurs.

---

### `xmlSecBufferGetMaxSize`

```c
xmlSecSize xmlSecBufferGetMaxSize(xmlSecBufferPtr buf);
```

*Source:* [include/xmlsec/buffer.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/buffer.h#L65)

Gets the maximum (allocated) buffer size.

**Parameters:**

- `buf` — the pointer to buffer object.


**Returns:** the maximum (allocated) buffer size.

---

### `xmlSecBufferSetMaxSize`

```c
int xmlSecBufferSetMaxSize(xmlSecBufferPtr buf, xmlSecSize size);
```

*Source:* [include/xmlsec/buffer.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/buffer.h#L66)

Sets new buffer maximum size.

Sets new buffer maximum size. If necessary, buffer grows to have at least `size` bytes. 

**Parameters:**

- `buf` — the pointer to buffer object.
- `size` — the new maximum size.


**Returns:** 0 on success or a negative value if an error occurs.

---

### `xmlSecBufferEmpty`

```c
void xmlSecBufferEmpty(xmlSecBufferPtr buf);
```

*Source:* [include/xmlsec/buffer.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/buffer.h#L68)

Empties the buffer.

**Parameters:**

- `buf` — the pointer to buffer object.

---

### `xmlSecBufferSwap`

```c
void xmlSecBufferSwap(xmlSecBufferPtr buf1, xmlSecBufferPtr buf2);
```

*Source:* [include/xmlsec/buffer.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/buffer.h#L69)

Swaps the content of the two buffers.

**Parameters:**

- `buf1` — the pointer to the first buffer object.
- `buf2` — the pointer to the second buffer object.

---

### `xmlSecBufferAppend`

```c
int xmlSecBufferAppend(xmlSecBufferPtr buf, const xmlSecByte *data, xmlSecSize size);
```

*Source:* [include/xmlsec/buffer.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/buffer.h#L71)

Appends data to the end of the buffer.

Appends the `data` after the current data stored in the buffer. 

**Parameters:**

- `buf` — the pointer to buffer object.
- `data` — the data.
- `size` — the data size.


**Returns:** 0 on success or a negative value if an error occurs.

---

### `xmlSecBufferPrepend`

```c
int xmlSecBufferPrepend(xmlSecBufferPtr buf, const xmlSecByte *data, xmlSecSize size);
```

*Source:* [include/xmlsec/buffer.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/buffer.h#L74)

Prepends data to the beginning of the buffer.

Prepends the `data` before the current data stored in the buffer. 

**Parameters:**

- `buf` — the pointer to buffer object.
- `data` — the data.
- `size` — the data size.


**Returns:** 0 on success or a negative value if an error occurs.

---

### `xmlSecBufferRemoveHead`

```c
int xmlSecBufferRemoveHead(xmlSecBufferPtr buf, xmlSecSize size);
```

*Source:* [include/xmlsec/buffer.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/buffer.h#L77)

Removes bytes from the beginning of the buffer.

Removes `size` bytes from the beginning of the current buffer. 

**Parameters:**

- `buf` — the pointer to buffer object.
- `size` — the number of bytes to be removed.


**Returns:** 0 on success or a negative value if an error occurs.

---

### `xmlSecBufferRemoveTail`

```c
int xmlSecBufferRemoveTail(xmlSecBufferPtr buf, xmlSecSize size);
```

*Source:* [include/xmlsec/buffer.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/buffer.h#L79)

Removes bytes from the end of the buffer.

Removes `size` bytes from the end of current buffer. 

**Parameters:**

- `buf` — the pointer to buffer object.
- `size` — the number of bytes to be removed.


**Returns:** 0 on success or a negative value if an error occurs.

---

### `xmlSecBufferReverse`

```c
int xmlSecBufferReverse(xmlSecBufferPtr buf);
```

*Source:* [include/xmlsec/buffer.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/buffer.h#L81)

Reverses order of bytes in the buffer `buf`.

**Parameters:**

- `buf` — the pointer to buffer object.


**Returns:** 0 on success or a negative value if an error occurs.

---

### `xmlSecBufferReadFile`

```c
int xmlSecBufferReadFile(xmlSecBufferPtr buf, const char *filename);
```

*Source:* [include/xmlsec/buffer.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/buffer.h#L82)

Reads the content of a file into the buffer.

Reads the content of the file `filename` in the buffer. 

**Parameters:**

- `buf` — the pointer to buffer object.
- `filename` — the filename.


**Returns:** 0 on success or a negative value if an error occurs.

---

### `xmlSecBufferBase64NodeContentRead`

```c
int xmlSecBufferBase64NodeContentRead(xmlSecBufferPtr buf, xmlNodePtr node);
```

*Source:* [include/xmlsec/buffer.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/buffer.h#L84)

Reads and base64-decodes a node's content into the buffer.

Reads the content of the `node`, base64 decodes it and stores the result in the buffer. 

**Parameters:**

- `buf` — the pointer to buffer object.
- `node` — the pointer to node.


**Returns:** 0 on success or a negative value if an error occurs.

---

### `xmlSecBufferBase64NodeContentWrite`

```c
int xmlSecBufferBase64NodeContentWrite(xmlSecBufferPtr buf, xmlNodePtr node, int columns);
```

*Source:* [include/xmlsec/buffer.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/buffer.h#L86)

Sets node content to the base64-encoded buffer data.

Sets the content of the `node` to the base64 encoded buffer data. 

**Parameters:**

- `buf` — the pointer to buffer object.
- `node` — the pointer to a node.
- `columns` — the max line size for base64 encoded data.


**Returns:** 0 on success or a negative value if an error occurs.

---

### `xmlSecBufferHexRead`

```c
int xmlSecBufferHexRead(xmlSecBufferPtr buf, const xmlChar *hexStr);
```

*Source:* [include/xmlsec/buffer.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/buffer.h#L89)

Reads hex-encoded string into the buffer.

Reads content of hex encoded `hexStr` into `buf`. 

**Parameters:**

- `buf` — the pointer to buffer object.
- `hexStr` — the hex string.


**Returns:** 0 on success or a negative value if an error occurs.

---

### `xmlSecBufferDebugHexDump`

```c
void xmlSecBufferDebugHexDump(xmlSecBufferPtr buf, FILE *output);
```

*Source:* [include/xmlsec/buffer.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/buffer.h#L92)

Writes the content of the buffer as hex string to the output.

Writes the content of the `buf` as hex string to the `output` (no more than 32 bytes per line). 

**Parameters:**

- `buf` — the pointer to buffer object.
- `output` — the pointer to output FILE.

---

### `xmlSecBufferCreateOutputBuffer`

```c
xmlOutputBufferPtr xmlSecBufferCreateOutputBuffer(xmlSecBufferPtr buf);
```

*Source:* [include/xmlsec/buffer.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/buffer.h#L95)

Creates a LibXML output buffer to store data in `buf`.

Creates new LibXML output buffer to store data in the `buf`. Caller is responsible for destroying `buf` when processing is done. 

**Parameters:**

- `buf` — the pointer to buffer.


**Returns:** pointer to newly allocated output buffer or NULL if an error occurs.

---
