2 Unix SMB/CIFS implementation.
6 Copyright (C) Kamen Mazdrashki <kamen.mazdrashki@postpath.com> 2009
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "torture/torture.h"
27 const char *oid; /* String OID */
28 const char *bin_oid; /* Binary OID represented as string */
31 /* Data for successfull OIDs conversions */
32 struct oid_data oid_data_ok[] = {
51 .bin_oid = "5504818003"
55 .bin_oid = "5581800304"
58 .oid = "2.5.2097155.4",
59 .bin_oid = "558180800304"
62 .oid = "2.5.4.130.16387.2097155.268435459",
63 .bin_oid = "55048102818003818080038180808003"
67 /* Data for successfull Partial OIDs conversions */
68 struct oid_data partial_oid_data_ok[] = {
70 .oid = "2.5.4.130:0x81",
71 .bin_oid = "5504810281"
74 .oid = "2.5.4.16387:0x8180",
75 .bin_oid = "55048180038180"
78 .oid = "2.5.4.16387:0x81",
79 .bin_oid = "550481800381"
82 .oid = "2.5.2097155.4:0x818080",
83 .bin_oid = "558180800304818080"
86 .oid = "2.5.2097155.4:0x8180",
87 .bin_oid = "5581808003048180"
90 .oid = "2.5.2097155.4:0x81",
91 .bin_oid = "55818080030481"
96 /* Testing ber_write_OID_String() function */
97 static bool test_ber_write_OID_String(struct torture_context *tctx)
103 struct oid_data *data = oid_data_ok;
105 mem_ctx = talloc_new(NULL);
107 for (i = 0; i < ARRAY_SIZE(oid_data_ok); i++) {
108 torture_assert(tctx, ber_write_OID_String(&blob, data[i].oid),
109 "ber_write_OID_String failed");
111 hex_str = hex_encode_talloc(mem_ctx, blob.data, blob.length);
112 torture_assert(tctx, hex_str, "No memory!");
114 torture_assert(tctx, strequal(data[i].bin_oid, hex_str),
115 talloc_asprintf(mem_ctx,
116 "Failed: oid=%s, bin_oid:%s",
117 data[i].oid, data[i].bin_oid));
120 talloc_free(mem_ctx);
125 /* Testing ber_write_partial_OID_String() function */
126 static bool test_ber_write_partial_OID_String(struct torture_context *tctx)
132 struct oid_data *data = oid_data_ok;
134 mem_ctx = talloc_new(NULL);
136 /* ber_write_partial_OID_String() should work with not partial OIDs also */
137 for (i = 0; i < ARRAY_SIZE(oid_data_ok); i++) {
138 torture_assert(tctx, ber_write_partial_OID_String(&blob, data[i].oid),
139 "ber_write_OID_String failed");
141 hex_str = hex_encode_talloc(mem_ctx, blob.data, blob.length);
142 torture_assert(tctx, hex_str, "No memory!");
144 torture_assert(tctx, strequal(data[i].bin_oid, hex_str),
145 talloc_asprintf(mem_ctx,
146 "Failed: oid=%s, bin_oid:%s",
147 data[i].oid, data[i].bin_oid));
150 /* ber_write_partial_OID_String() test with partial OIDs */
151 data = partial_oid_data_ok;
152 for (i = 0; i < ARRAY_SIZE(partial_oid_data_ok); i++) {
153 torture_assert(tctx, ber_write_partial_OID_String(&blob, data[i].oid),
154 "ber_write_OID_String failed");
156 hex_str = hex_encode_talloc(mem_ctx, blob.data, blob.length);
157 torture_assert(tctx, hex_str, "No memory!");
159 torture_assert(tctx, strequal(data[i].bin_oid, hex_str),
160 talloc_asprintf(mem_ctx,
161 "Failed: oid=%s, bin_oid:%s",
162 data[i].oid, data[i].bin_oid));
165 talloc_free(mem_ctx);
171 /* LOCAL-ASN1 test suite creation */
172 struct torture_suite *torture_local_util_asn1(TALLOC_CTX *mem_ctx)
174 struct torture_suite *suite = torture_suite_create(mem_ctx, "ASN1");
176 torture_suite_add_simple_test(suite, "ber_write_OID_String",
177 test_ber_write_OID_String);
179 torture_suite_add_simple_test(suite, "ber_write_partial_OID_String",
180 test_ber_write_partial_OID_String);