Webserver+3d print

Dependents:   Nucleo

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers asn1.h Source File

asn1.h

Go to the documentation of this file.
00001 /**
00002  * @file asn1.h
00003  * @brief ASN.1 (Abstract Syntax Notation One)
00004  *
00005  * @section License
00006  *
00007  * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved.
00008  *
00009  * This file is part of CycloneCrypto Open.
00010  *
00011  * This program is free software; you can redistribute it and/or
00012  * modify it under the terms of the GNU General Public License
00013  * as published by the Free Software Foundation; either version 2
00014  * of the License, or (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software Foundation,
00023  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00024  *
00025  * @author Oryx Embedded SARL (www.oryx-embedded.com)
00026  * @version 1.7.6
00027  **/
00028 
00029 #ifndef _ASN1_H
00030 #define _ASN1_H
00031 
00032 //Dependencies
00033 #include "crypto.h"
00034 
00035 //Tag number mask
00036 #define ASN1_TAG_NUMBER_MASK        0x1F
00037 
00038 //ASN.1 encoding
00039 #define ASN1_ENCODING_MASK          0x20
00040 #define ASN1_ENCODING_PRIMITIVE     0x00
00041 #define ASN1_ENCODING_CONSTRUCTED   0x20
00042 
00043 //ASN.1 class
00044 #define ASN1_CLASS_MASK             0xC0
00045 #define ASN1_CLASS_UNIVERSAL        0x00
00046 #define ASN1_CLASS_APPLICATION      0x40
00047 #define ASN1_CLASS_CONTEXT_SPECIFIC 0x80
00048 #define ASN1_CLASS_PRIVATE          0xC0
00049 
00050 
00051 /**
00052  * @brief ASN.1 data types
00053  **/
00054 
00055 typedef enum
00056 {
00057    ASN1_TYPE_BOOLEAN           = 1,
00058    ASN1_TYPE_INTEGER           = 2,
00059    ASN1_TYPE_BIT_STRING        = 3,
00060    ASN1_TYPE_OCTET_STRING      = 4,
00061    ASN1_TYPE_NULL              = 5,
00062    ASN1_TYPE_OBJECT_IDENTIFIER = 6,
00063    ASN1_TYPE_OBJECT_DESCRIPTOR = 7,
00064    ASN1_TYPE_EXTERNAL          = 8,
00065    ASN1_TYPE_REAL              = 9,
00066    ASN1_TYPE_ENUMERATED        = 10,
00067    ASN1_TYPE_UTF8_STRING       = 12,
00068    ASN1_TYPE_SEQUENCE          = 16,
00069    ASN1_TYPE_SET               = 17,
00070    ASN1_TYPE_NUMERIC_STRING    = 18,
00071    ASN1_TYPE_PRINTABLE_STRING  = 19,
00072    ASN1_TYPE_TELETEX_STRING    = 20,
00073    ASN1_TYPE_VIDEOTEX_STRING   = 21,
00074    ASN1_TYPE_IA5_STRING        = 22,
00075    ASN1_TYPE_UTC_TIME          = 23,
00076    ASN1_TYPE_GENERALIZED_TIME  = 24,
00077    ASN1_TYPE_GRAPHIC_STRING    = 25,
00078    ASN1_TYPE_VISIBLE_STRING    = 26,
00079    ASN1_TYPE_GENERAL_STRING    = 27,
00080    ASN1_TYPE_UNIVERSAL_STRING  = 28,
00081    ASN1_TYPE_BMP_STRING        = 30,
00082 } Asn1Type;
00083 
00084 
00085 /**
00086  * @brief ASN.1 tag
00087  **/
00088 
00089 typedef struct
00090 {
00091    bool_t constructed;
00092    uint_t objClass;
00093    uint_t objType;
00094    size_t length;
00095    const uint8_t *value;
00096    size_t totalLength;
00097 } Asn1Tag;
00098 
00099 
00100 //ASN.1 related functions
00101 error_t asn1ReadTag(const uint8_t *data, size_t length, Asn1Tag *tag);
00102 error_t asn1ReadInt32(const uint8_t *data, size_t length, Asn1Tag *tag, int32_t *value);
00103 
00104 error_t asn1WriteTag(Asn1Tag *tag, bool_t reverse, uint8_t *data, size_t *written);
00105 error_t asn1WriteInt32(int32_t value, bool_t reverse, uint8_t *data, size_t *written);
00106 
00107 error_t asn1CheckTag(const Asn1Tag *tag, bool_t constructed, uint_t objClass, uint_t objType);
00108 error_t asn1CheckOid(const Asn1Tag *tag, const uint8_t *oid, size_t length);
00109 
00110 error_t asn1DumpObject(const uint8_t *data, size_t length, uint_t level);
00111 
00112 #endif
00113