oid.h
Go to the documentation of this file.
1 /**
2  * @file oid.h
3  * @brief OID (Object Identifier)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2025 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneCRYPTO Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.5.0
29  **/
30 
31 #ifndef _OID_H
32 #define _OID_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 
37 //Mask definition
38 #define OID_MORE_FLAG 0x80
39 #define OID_VALUE_MASK 0x7F
40 
41 //Compare object identifiers
42 #define OID_COMP(oid1, oidLen1, oid2) oidComp(oid1, oidLen1, oid2, sizeof(oid2))
43 
44 //C++ guard
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 //OID related functions
50 error_t oidCheck(const uint8_t *oid, size_t oidLen);
51 
52 int_t oidComp(const uint8_t *oid1, size_t oidLen1, const uint8_t *oid2,
53  size_t oidLen2);
54 
55 bool_t oidMatch(const uint8_t *oid, size_t oidLen, const uint8_t *subtree,
56  size_t subtreeLen, const uint8_t *mask, size_t maskLen);
57 
58 uint_t oidCountSubIdentifiers(const uint8_t *oid, size_t oidLen);
59 
60 error_t oidEncodeSubIdentifier(uint8_t *oid, size_t maxOidLen,
61  size_t *pos, uint32_t value);
62 
63 error_t oidDecodeSubIdentifier(const uint8_t *oid, size_t oidLen,
64  size_t *pos, uint32_t *value);
65 
66 error_t oidFromString(const char_t *str, uint8_t *oid, size_t maxOidLen,
67  size_t *oidLen);
68 
69 char_t *oidToString(const uint8_t *oid, size_t oidLen, char_t *str,
70  size_t maxStrLen);
71 
72 error_t maskFromString(const char_t *str, uint8_t *mask, size_t maxMaskLen,
73  size_t *maskLen);
74 
75 //C++ guard
76 #ifdef __cplusplus
77 }
78 #endif
79 
80 #endif
error_t maskFromString(const char_t *str, uint8_t *mask, size_t maxMaskLen, size_t *maskLen)
Convert a bit mask to binary representation.
Definition: oid.c:746
int_t oidComp(const uint8_t *oid1, size_t oidLen1, const uint8_t *oid2, size_t oidLen2)
Compare object identifiers.
Definition: oid.c:103
int bool_t
Definition: compiler_port.h:61
signed int int_t
Definition: compiler_port.h:56
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.
Definition: oid.c:519
uint8_t oid[]
Definition: lldp_tlv.h:300
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.
Definition: oid.c:245
error_t
Error codes.
Definition: error.h:43
General definitions for cryptographic algorithms.
error_t oidEncodeSubIdentifier(uint8_t *oid, size_t maxOidLen, size_t *pos, uint32_t value)
Encode OID sub-identifier.
Definition: oid.c:427
uint8_t mask
Definition: web_socket.h:319
char char_t
Definition: compiler_port.h:55
error_t oidDecodeSubIdentifier(const uint8_t *oid, size_t oidLen, size_t *pos, uint32_t *value)
Decode OID sub-identifier.
Definition: oid.c:475
uint_t oidCountSubIdentifiers(const uint8_t *oid, size_t oidLen)
Calculate the number of sub-identifiers.
Definition: oid.c:386
uint8_t value[]
Definition: tcp.h:376
uint8_t oidLen
Definition: lldp_tlv.h:299
char_t * oidToString(const uint8_t *oid, size_t oidLen, char_t *str, size_t maxStrLen)
Convert a binary OID to a string representation.
Definition: oid.c:659
unsigned int uint_t
Definition: compiler_port.h:57
error_t oidCheck(const uint8_t *oid, size_t oidLen)
Check whether the specified object identifier is valid.
Definition: oid.c:50