# Keys Manager

**API Group:** `xmlsec_core_keysmngr`

Keys manager — locating and verifying keys.

Keys manager object functions.

## Macros

### `xmlSecKeyStoreGetName`

*Defined as:* `((xmlSecKeyStoreIsValid((store))) ? \
      xmlSecKeyStoreKlassGetName((store)->id) : NULL)`

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

Macro. Returns key store name.

**Parameters:**

- `store` — the pointer to store.

---

### `xmlSecKeyStoreIsValid`

*Defined as:* `((( store ) != NULL) && ((( store )->id) != NULL))`

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

Macro. Returns 1 if store is not NULL and store->id is not NULL.

Macro. Returns 1 if `store` is not NULL and `store->id` is not NULL or 0 otherwise. 

**Parameters:**

- `store` — the pointer to store.

---

### `xmlSecKeyStoreCheckId`

*Defined as:* `(xmlSecKeyStoreIsValid(( store )) && \
        ((( store )->id) == ( storeId )))`

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

Macro. Returns 1 if store is valid and store id matches storeId.

Macro. Returns 1 if `store` is valid and `store's` id is equal to `storeId`. 

**Parameters:**

- `store` — the pointer to store.
- `storeId` — the store Id.

---

### `xmlSecKeyStoreCheckSize`

*Defined as:* `(xmlSecKeyStoreIsValid(( store )) && \
         (( store )->id->objSize >= size))`

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

Macro. Returns 1 if store is valid and object size meets minimum.

Macro. Returns 1 if `store` is valid and `stores's` object has at least `size` bytes. 

**Parameters:**

- `store` — the pointer to store.
- `size` — the expected size.

---

### `xmlSecKeyStoreIdUnknown`

*Defined as:* `((xmlSecKeyDataStoreId)NULL)`

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

The "unknown" id.

---

### `xmlSecKeyStoreKlassGetName`

*Defined as:* `(((klass)) ? ((klass)->name) : NULL)`

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

Macro. Returns store klass name.

**Parameters:**

- `klass` — the pointer to store klass.

---

### `xmlSecSimpleKeysStoreId`

*Defined as:* `xmlSecSimpleKeysStoreGetKlass()`

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

A simple keys store klass id.

---

## Typedefs

### `xmlSecKeyKlass`

```c
typedef const struct _xmlSecKeyKlass xmlSecKeyKlass;
```

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

The key klass.

---

### `xmlSecKeyId`

```c
typedef const struct _xmlSecKeyKlass* xmlSecKeyId;
```

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

Pointer to `xmlSecKeyKlass`.

---

### `xmlSecKeyStoreKlass`

```c
typedef const struct _xmlSecKeyStoreKlass xmlSecKeyStoreKlass;
```

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

The key store klass.

---

### `xmlSecKeyStoreId`

```c
typedef const struct _xmlSecKeyStoreKlass* xmlSecKeyStoreId;
```

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

Pointer to `xmlSecKeyStoreKlass`.

---

### `xmlSecGetKeyCallback`

```c
typedef xmlSecKeyPtr(* xmlSecGetKeyCallback) (xmlNodePtr keyInfoNode, xmlSecKeyInfoCtxPtr keyInfoCtx))(xmlNodePtr keyInfoNode, xmlSecKeyInfoCtxPtr keyInfoCtx);
```

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

Reads the <dsig:KeyInfo/> node and extracts the key.

Reads the <dsig:KeyInfo/> node `keyInfoNode` and extracts the key. 

**Parameters:**

- `keyInfoNode` — the pointer to <dsig:KeyInfo/> node.
- `keyInfoCtx` — the pointer to <dsig:KeyInfo/> node processing context.


**Returns:** the pointer to key or NULL if the key is not found or an error occurs.

---

### `xmlSecKeyStoreInitializeMethod`

```c
typedef int(* xmlSecKeyStoreInitializeMethod) (xmlSecKeyStorePtr store))(xmlSecKeyStorePtr store);
```

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

Keys store specific initialization method.

**Parameters:**

- `store` — the store.


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

---

### `xmlSecKeyStoreFinalizeMethod`

```c
typedef void(* xmlSecKeyStoreFinalizeMethod) (xmlSecKeyStorePtr store))(xmlSecKeyStorePtr store);
```

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

Keys store specific finalization (destroy) method.

**Parameters:**

- `store` — the store.

---

### `xmlSecKeyStoreFindKeyMethod`

```c
typedef xmlSecKeyPtr(* xmlSecKeyStoreFindKeyMethod) (xmlSecKeyStorePtr store, const xmlChar *name, xmlSecKeyInfoCtxPtr keyInfoCtx))(xmlSecKeyStorePtr store, const xmlChar *name, xmlSecKeyInfoCtxPtr keyInfoCtx);
```

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

Keys store specific find method by key name.

Keys store specific find method. The caller is responsible for destroying the returned key using `xmlSecKeyDestroy` method. 

**Parameters:**

- `store` — the store.
- `name` — the desired key name.
- `keyInfoCtx` — the pointer to key info context.


**Returns:** the pointer to a key or NULL if key is not found or an error occurs.

---

### `xmlSecKeyStoreFindKeyFromX509DataMethod`

```c
typedef xmlSecKeyPtr(* xmlSecKeyStoreFindKeyFromX509DataMethod) (xmlSecKeyStorePtr store, xmlSecKeyX509DataValuePtr x509Data, xmlSecKeyInfoCtxPtr keyInfoCtx))(xmlSecKeyStorePtr store, xmlSecKeyX509DataValuePtr x509Data, xmlSecKeyInfoCtxPtr keyInfoCtx);
```

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

Keys store specific find method by X509 data.

Keys store specific find method. The caller is responsible for destroying the returned key using `xmlSecKeyDestroy` method. 

**Parameters:**

- `store` — the store.
- `x509Data` — the x509 data to lookup key.
- `keyInfoCtx` — the pointer to key info context.


**Returns:** the pointer to a key or NULL if key is not found or an error occurs.

---

### `xmlSecSimpleKeysStoreAdoptKeyFunc`

```c
typedef int(* xmlSecSimpleKeysStoreAdoptKeyFunc) (xmlSecKeyStorePtr store, xmlSecKeyPtr key))(xmlSecKeyStorePtr store, xmlSecKeyPtr key);
```

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

Adds `key` to the `store`.

Adds `key` to the `store`. On success, the `store` owns the `key`. 

**Parameters:**

- `store` — the pointer to key store.
- `key` — the pointer to key.


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

---

## Functions

### `xmlSecKeysMngrCreate`

```c
xmlSecKeysMngrPtr xmlSecKeysMngrCreate(void);
```

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

Creates a new keys manager.

Creates new keys manager. Caller is responsible for freeing it with `xmlSecKeysMngrDestroy` function.

**Returns:** the pointer to newly allocated keys manager or NULL if an error occurs.

---

### `xmlSecKeysMngrDestroy`

```c
void xmlSecKeysMngrDestroy(xmlSecKeysMngrPtr mngr);
```

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

Destroys a keys manager.

Destroys keys manager created with `xmlSecKeysMngrCreate` function. 

**Parameters:**

- `mngr` — the pointer to keys manager.

---

### `xmlSecKeysMngrFindKey`

```c
xmlSecKeyPtr xmlSecKeysMngrFindKey(xmlSecKeysMngrPtr mngr, const xmlChar *name, xmlSecKeyInfoCtxPtr keyInfoCtx);
```

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

Looks up a key in the keys manager keys store.

Lookups key in the keys manager keys store. The caller is responsible for destroying the returned key using `xmlSecKeyDestroy` method. 

**Parameters:**

- `mngr` — the pointer to keys manager.
- `name` — the desired key name.
- `keyInfoCtx` — the pointer to <dsig:KeyInfo/> node processing context.


**Returns:** the pointer to a key or NULL if key is not found or an error occurs.

---

### `xmlSecKeysMngrFindKeyFromX509Data`

```c
xmlSecKeyPtr xmlSecKeysMngrFindKeyFromX509Data(xmlSecKeysMngrPtr mngr, xmlSecKeyX509DataValuePtr x509Data, xmlSecKeyInfoCtxPtr keyInfoCtx);
```

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

Looks up a key by X.509 data in the keys manager keys store.

Lookups key in the keys manager keys store. The caller is responsible for destroying the returned key using `xmlSecKeyDestroy` method. 

**Parameters:**

- `mngr` — the pointer to keys manager.
- `x509Data` — the X509 data to use for searching the keys.
- `keyInfoCtx` — the pointer to <dsig:KeyInfo/> node processing context.


**Returns:** the pointer to a key or NULL if key is not found or an error occurs.

---

### `xmlSecKeysMngrAdoptKeysStore`

```c
int xmlSecKeysMngrAdoptKeysStore(xmlSecKeysMngrPtr mngr, xmlSecKeyStorePtr store);
```

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

Adopts keys store in the keys manager `mngr`.

**Parameters:**

- `mngr` — the pointer to keys manager.
- `store` — the pointer to keys store.


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

---

### `xmlSecKeysMngrGetKeysStore`

```c
xmlSecKeyStorePtr xmlSecKeysMngrGetKeysStore(xmlSecKeysMngrPtr mngr);
```

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

Gets the keys store.

**Parameters:**

- `mngr` — the pointer to keys manager.


**Returns:** the keys store in the keys manager `mngr` or NULL if there is no store or an error occurs.

---

### `xmlSecKeysMngrAdoptDataStore`

```c
int xmlSecKeysMngrAdoptDataStore(xmlSecKeysMngrPtr mngr, xmlSecKeyDataStorePtr store);
```

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

Adopts data store in the keys manager.

**Parameters:**

- `mngr` — the pointer to keys manager.
- `store` — the pointer to data store.


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

---

### `xmlSecKeysMngrGetDataStore`

```c
xmlSecKeyDataStorePtr xmlSecKeysMngrGetDataStore(xmlSecKeysMngrPtr mngr, xmlSecKeyDataStoreId id);
```

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

Looks up a data store by klass in the keys manager.

Lookups the data store of given klass `id` in the keys manager. 

**Parameters:**

- `mngr` — the pointer to keys manager.
- `id` — the desired data store klass.


**Returns:** pointer to data store or NULL if it is not found or an error occurs.

---

### `xmlSecKeysMngrGetKey`

```c
xmlSecKeyPtr xmlSecKeysMngrGetKey(xmlNodePtr keyInfoNode, xmlSecKeyInfoCtxPtr keyInfoCtx);
```

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

Reads a KeyInfo node and extracts the key.

Reads the <dsig:KeyInfo/> node `keyInfoNode` and extracts the key. 

**Parameters:**

- `keyInfoNode` — the pointer to <dsig:KeyInfo/> node.
- `keyInfoCtx` — the pointer to <dsig:KeyInfo/> node processing context.


**Returns:** the pointer to key or NULL if the key is not found or an error occurs.

---

### `xmlSecKeyStoreCreate`

```c
xmlSecKeyStorePtr xmlSecKeyStoreCreate(xmlSecKeyStoreId id);
```

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

Creates a new keys store of the specified klass.

Creates new store of the specified klass `klass`. Caller is responsible for freeing the returned store by calling `xmlSecKeyStoreDestroy` function. 

**Parameters:**

- `id` — the key store klass.


**Returns:** the pointer to newly allocated keys store or NULL if an error occurs.

---

### `xmlSecKeyStoreDestroy`

```c
void xmlSecKeyStoreDestroy(xmlSecKeyStorePtr store);
```

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

Destroys a keys store.

Destroys the store created with `xmlSecKeyStoreCreate` function. 

**Parameters:**

- `store` — the pointer to keys store.

---

### `xmlSecKeyStoreFindKey`

```c
xmlSecKeyPtr xmlSecKeyStoreFindKey(xmlSecKeyStorePtr store, const xmlChar *name, xmlSecKeyInfoCtxPtr keyInfoCtx);
```

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

Looks up a key in the store by name.

Lookups key in the store. The caller is responsible for destroying the returned key using `xmlSecKeyDestroy` method. 

**Parameters:**

- `store` — the pointer to keys store.
- `name` — the desired key name.
- `keyInfoCtx` — the pointer to <dsig:KeyInfo/> node processing context.


**Returns:** the pointer to a key or NULL if key is not found or an error occurs.

---

### `xmlSecKeyStoreFindKeyFromX509Data`

```c
xmlSecKeyPtr xmlSecKeyStoreFindKeyFromX509Data(xmlSecKeyStorePtr store, xmlSecKeyX509DataValuePtr x509Data, xmlSecKeyInfoCtxPtr keyInfoCtx);
```

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

Looks up a key by X.509 data in the store.

Lookups key in the store. The caller is responsible for destroying the returned key using `xmlSecKeyDestroy` method. 

**Parameters:**

- `store` — the pointer to keys store.
- `x509Data` — the X509 data to use for search.
- `keyInfoCtx` — the pointer to <dsig:KeyInfo/> node processing context.


**Returns:** the pointer to a key or NULL if key is not found or an error occurs.

---

### `xmlSecSimpleKeysStoreGetKlass`

```c
xmlSecKeyStoreId xmlSecSimpleKeysStoreGetKlass(void);
```

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

The simple list based keys store klass.

**Returns:** simple list based keys store klass.

---

### `xmlSecSimpleKeysStoreAdoptKey`

```c
int xmlSecSimpleKeysStoreAdoptKey(xmlSecKeyStorePtr store, xmlSecKeyPtr key);
```

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

Adds `key` to the `store`.

**Parameters:**

- `store` — the pointer to simple keys store.
- `key` — the pointer to key.


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

---

### `xmlSecSimpleKeysStoreLoad`

```c
int xmlSecSimpleKeysStoreLoad(xmlSecKeyStorePtr store, const char *uri, xmlSecKeysMngrPtr keysMngr);
```

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

Reads keys from an XML file.

**Parameters:**

- `store` — the pointer to simple keys store.
- `uri` — the filename.
- `keysMngr` — the pointer to associated keys manager.


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

---

### `xmlSecSimpleKeysStoreLoad_ex`

```c
int xmlSecSimpleKeysStoreLoad_ex(xmlSecKeyStorePtr store, const char *uri, xmlSecKeysMngrPtr keysMngr, xmlSecSimpleKeysStoreAdoptKeyFunc adoptKeyFunc);
```

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

Reads keys from an XML file using a custom adopt callback.

Reads keys from an XML file. 

**Parameters:**

- `store` — the pointer to simple keys store.
- `uri` — the filename.
- `keysMngr` — the pointer to associated keys manager.
- `adoptKeyFunc` — the callback to add the key to keys manager.


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

---

### `xmlSecSimpleKeysStoreSave`

```c
int xmlSecSimpleKeysStoreSave(xmlSecKeyStorePtr store, const char *filename, xmlSecKeyDataType type);
```

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

Writes keys from `store` to an XML file.

**Parameters:**

- `store` — the pointer to simple keys store.
- `filename` — the filename.
- `type` — the saved keys type (public, private, ...).


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

---

### `xmlSecSimpleKeysStoreGetKeys`

```c
xmlSecPtrListPtr xmlSecSimpleKeysStoreGetKeys(xmlSecKeyStorePtr store);
```

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

Gets list of keys from simple keys store.

**Parameters:**

- `store` — the pointer to simple keys store.


**Returns:** pointer to the list of keys stored in the keys store or NULL if an error occurs.

---
