oid.c File Reference

OID (Object Identifier) More...

#include "core/crypto.h"
#include "encoding/oid.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL
 

Functions

error_t oidCheck (const uint8_t *oid, size_t oidLen)
 Check whether the specified object identifier is valid. More...
 
int_t oidComp (const uint8_t *oid1, size_t oidLen1, const uint8_t *oid2, size_t oidLen2)
 Compare object identifiers. More...
 
bool_t oidMatch (const uint8_t *oid, size_t oidLen, const uint8_t *subtree, size_t subtreeLen, const uint8_t *mask, size_t maskLen)
 Check whether an OID matches the specified subtree. More...
 
uint_t oidCountSubIdentifiers (const uint8_t *oid, size_t oidLen)
 Calculate the number of sub-identifiers. More...
 
error_t oidEncodeSubIdentifier (uint8_t *oid, size_t maxOidLen, size_t *pos, uint32_t value)
 Encode OID sub-identifier. More...
 
error_t oidDecodeSubIdentifier (const uint8_t *oid, size_t oidLen, size_t *pos, uint32_t *value)
 Decode OID sub-identifier. More...
 
error_t oidFromString (const char_t *str, uint8_t *oid, size_t maxOidLen, size_t *oidLen)
 Convert a string representation of an OID to a binary OID. More...
 
char_toidToString (const uint8_t *oid, size_t oidLen, char_t *str, size_t maxStrLen)
 Convert a binary OID to a string representation. More...
 
error_t maskFromString (const char_t *str, uint8_t *mask, size_t maxMaskLen, size_t *maskLen)
 Convert a bit mask to binary representation. More...
 

Detailed Description

OID (Object Identifier)

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneCRYPTO Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.4.0

Definition in file oid.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL

Definition at line 32 of file oid.c.

Function Documentation

◆ maskFromString()

error_t maskFromString ( const char_t str,
uint8_t *  mask,
size_t  maxMaskLen,
size_t *  maskLen 
)

Convert a bit mask to binary representation.

Parameters
[in]strNULL-terminated string representing the bit mask
[out]maskPointer to the buffer where to store the resulting mask
[in]maxMaskLenMaximum number of bytes the buffer can hold
[out]maskLenLength of the mask
Returns
Error code

Definition at line 746 of file oid.c.

◆ oidCheck()

error_t oidCheck ( const uint8_t *  oid,
size_t  oidLen 
)

Check whether the specified object identifier is valid.

Parameters
[in]oidPointer to the object identifier
[in]oidLenLength of the OID, in bytes
Returns
Error code

Definition at line 50 of file oid.c.

◆ oidComp()

int_t oidComp ( const uint8_t *  oid1,
size_t  oidLen1,
const uint8_t *  oid2,
size_t  oidLen2 
)

Compare object identifiers.

Parameters
[in]oid1Pointer the first OID
[in]oidLen1Length of the first OID, in bytes
[in]oid2Pointer the second OID
[in]oidLen2Length of the second OID, in bytes
Returns
Comparison result
Return values
0Objects identifiers are equal
-1The first OID lexicographically precedes the second OID
1The second OID lexicographically precedes the first OID

Definition at line 103 of file oid.c.

◆ oidCountSubIdentifiers()

uint_t oidCountSubIdentifiers ( const uint8_t *  oid,
size_t  oidLen 
)

Calculate the number of sub-identifiers.

Parameters
[in]oidPointer to the object identifier
[in]oidLenLength of the OID, in bytes
Returns
Number of sub-identifiers

Definition at line 386 of file oid.c.

◆ oidDecodeSubIdentifier()

error_t oidDecodeSubIdentifier ( const uint8_t *  oid,
size_t  oidLen,
size_t *  pos,
uint32_t *  value 
)

Decode OID sub-identifier.

Parameters
[in]oidPointer to the object identifier
[in]oidLenLength of the OID, in bytes
[in,out]posOffset where to read the sub-identifier
[out]valueValue of the sub-identifier
Returns
Error code

Definition at line 475 of file oid.c.

◆ oidEncodeSubIdentifier()

error_t oidEncodeSubIdentifier ( uint8_t *  oid,
size_t  maxOidLen,
size_t *  pos,
uint32_t  value 
)

Encode OID sub-identifier.

Parameters
[in]oidPointer to the object identifier
[in]maxOidLenMaximum number of bytes the OID can hold
[in,out]posOffset where to write the sub-identifier
[in]valueValue of the sub-identifier
Returns
Error code

Definition at line 427 of file oid.c.

◆ oidFromString()

error_t oidFromString ( const char_t str,
uint8_t *  oid,
size_t  maxOidLen,
size_t *  oidLen 
)

Convert a string representation of an OID to a binary OID.

Parameters
[in]strNULL-terminated string representing the OID
[out]oidObject identifier
[in]maxOidLenMaximum number of bytes the OID can hold
[out]oidLenLength of the object identifier
Returns
Error code

Definition at line 519 of file oid.c.

◆ oidMatch()

bool_t oidMatch ( const uint8_t *  oid,
size_t  oidLen,
const uint8_t *  subtree,
size_t  subtreeLen,
const uint8_t *  mask,
size_t  maskLen 
)

Check whether an OID matches the specified subtree.

Parameters
[in]oidPointer to the object identifier
[in]oidLenLength of the OID, in bytes
[in]subtreePointer to the subtree
[in]subtreeLenLength of the subtree, in bytes
[in]maskPointer to the mask
[in]maskLenLength of the mask, in bytes
Returns
TRUE if the OID matches the specified subtree, else FALSE

Definition at line 245 of file oid.c.

◆ oidToString()

char_t* oidToString ( const uint8_t *  oid,
size_t  oidLen,
char_t str,
size_t  maxStrLen 
)

Convert a binary OID to a string representation.

Parameters
[in]oidObject identifier
[in]oidLenLength of the object identifier, in bytes
[out]strNULL-terminated string representing the OID
[in]maxStrLenMaximum length of the resulting string
Returns
Pointer to the formatted string

Definition at line 659 of file oid.c.