VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/asn1/asn1-ut-null.cpp@ 53528

Last change on this file since 53528 was 51770, checked in by vboxsync, 11 years ago

Merged in iprt++ dev branch.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 KB
Line 
1/* $Id: asn1-ut-null.cpp 51770 2014-07-01 18:14:02Z vboxsync $ */
2/** @file
3 * IPRT - ASN.1, NULL type.
4 */
5
6/*
7 * Copyright (C) 2006-2014 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27/*******************************************************************************
28* Header Files *
29*******************************************************************************/
30#include "internal/iprt.h"
31#include <iprt/asn1.h>
32
33#include <iprt/err.h>
34#include <iprt/string.h>
35
36#include <iprt/formats/asn1.h>
37
38
39/*
40 * ASN.1 NULL - Special Methods.
41 */
42
43
44/*
45 * ASN.1 NULL - Standard Methods.
46 */
47
48
49RT_DECL_DATA_CONST(RTASN1COREVTABLE const) g_RTAsn1Null_Vtable =
50{
51 "RTAsn1Null",
52 sizeof(RTASN1NULL),
53 ASN1_TAG_NULL,
54 ASN1_TAGCLASS_UNIVERSAL | ASN1_TAGFLAG_PRIMITIVE,
55 0,
56 (PFNRTASN1COREVTDTOR)RTAsn1Null_Delete,
57 (PFNRTASN1COREVTENUM)RTAsn1Null_Enum,
58 (PFNRTASN1COREVTCLONE)RTAsn1Null_Clone,
59 (PFNRTASN1COREVTCOMPARE)RTAsn1Null_Compare,
60 (PFNRTASN1COREVTCHECKSANITY)RTAsn1Null_CheckSanity,
61 NULL,
62 NULL
63};
64
65
66RTDECL(int) RTAsn1Null_Init(PRTASN1NULL pThis, PCRTASN1ALLOCATORVTABLE pAllocator)
67{
68 return RTAsn1Core_InitEx(&pThis->Asn1Core, ASN1_TAG_NULL, ASN1_TAGCLASS_UNIVERSAL | ASN1_TAGFLAG_PRIMITIVE,
69 &g_RTAsn1Null_Vtable, RTASN1CORE_F_PRESENT | RTASN1CORE_F_PRIMITE_TAG_STRUCT);
70}
71
72
73RTDECL(int) RTAsn1Null_Clone(PRTASN1NULL pThis, PCRTASN1NULL pSrc, PCRTASN1ALLOCATORVTABLE pAllocator)
74{
75 AssertPtr(pSrc); AssertPtr(pThis); AssertPtr(pAllocator);
76 RT_ZERO(*pThis);
77 if (RTAsn1Null_IsPresent(pSrc))
78 {
79 AssertReturn(pSrc->Asn1Core.pOps == &g_RTAsn1Null_Vtable, VERR_INTERNAL_ERROR_3);
80 AssertReturn(pSrc->Asn1Core.cb == 0, VERR_INTERNAL_ERROR_4);
81
82 int rc = RTAsn1Core_CloneNoContent(&pThis->Asn1Core, &pSrc->Asn1Core);
83 if (RT_FAILURE(rc))
84 return rc;
85 }
86 return VINF_SUCCESS;
87}
88
89
90RTDECL(void) RTAsn1Null_Delete(PRTASN1NULL pThis)
91{
92 if ( pThis
93 && RTAsn1Null_IsPresent(pThis))
94 {
95 Assert(pThis->Asn1Core.pOps == &g_RTAsn1Null_Vtable);
96 RT_ZERO(*pThis);
97 }
98}
99
100
101RTDECL(int) RTAsn1Null_Enum(PRTASN1NULL pThis, PFNRTASN1ENUMCALLBACK pfnCallback, uint32_t uDepth, void *pvUser)
102{
103 Assert(pThis && (!RTAsn1Null_IsPresent(pThis) || pThis->Asn1Core.pOps == &g_RTAsn1Null_Vtable));
104
105 /* No children to enumerate. */
106 return VINF_SUCCESS;
107}
108
109
110RTDECL(int) RTAsn1Null_Compare(PCRTASN1NULL pLeft, PCRTASN1NULL pRight)
111{
112 Assert(pLeft && (!RTAsn1Null_IsPresent(pLeft) || pLeft->Asn1Core.pOps == &g_RTAsn1Null_Vtable));
113 Assert(pRight && (!RTAsn1Null_IsPresent(pRight) || pRight->Asn1Core.pOps == &g_RTAsn1Null_Vtable));
114
115 return (int)RTAsn1Null_IsPresent(pLeft) - (int)RTAsn1Null_IsPresent(pRight);
116}
117
118
119RTDECL(int) RTAsn1Null_CheckSanity(PCRTASN1NULL pThis, uint32_t fFlags, PRTERRINFO pErrInfo, const char *pszErrorTag)
120{
121 if (RT_UNLIKELY(!RTAsn1Null_IsPresent(pThis)))
122 return RTErrInfoSetF(pErrInfo, VERR_ASN1_NOT_PRESENT, "%s: Missing (NULL).", pszErrorTag);
123 return VINF_SUCCESS;
124}
125
126/* No NULL object collections. */
127
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette