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-2024 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.4.4
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 //C++ guard
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 //OID related functions
47 error_t oidCheck(const uint8_t *oid, size_t oidLen);
48 
49 int_t oidComp(const uint8_t *oid1, size_t oidLen1, const uint8_t *oid2,
50  size_t oidLen2);
51 
52 bool_t oidMatch(const uint8_t *oid, size_t oidLen, const uint8_t *subtree,
53  size_t subtreeLen, const uint8_t *mask, size_t maskLen);
54 
55 uint_t oidCountSubIdentifiers(const uint8_t *oid, size_t oidLen);
56 
57 error_t oidEncodeSubIdentifier(uint8_t *oid, size_t maxOidLen,
58  size_t *pos, uint32_t value);
59 
60 error_t oidDecodeSubIdentifier(const uint8_t *oid, size_t oidLen,
61  size_t *pos, uint32_t *value);
62 
63 error_t oidFromString(const char_t *str, uint8_t *oid, size_t maxOidLen,
64  size_t *oidLen);
65 
66 char_t *oidToString(const uint8_t *oid, size_t oidLen, char_t *str,
67  size_t maxStrLen);
68 
69 error_t maskFromString(const char_t *str, uint8_t *mask, size_t maxMaskLen,
70  size_t *maskLen);
71 
72 //C++ guard
73 #ifdef __cplusplus
74 }
75 #endif
76 
77 #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:53
signed int int_t
Definition: compiler_port.h:49
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:48
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:369
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:50
error_t oidCheck(const uint8_t *oid, size_t oidLen)
Check whether the specified object identifier is valid.
Definition: oid.c:50