X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?p=sim%2Fe2-interface.git;a=blobdiff_plain;f=e2sim%2Fprevious%2FASN1c%2Fasn_random_fill.c;fp=e2sim%2Fprevious%2FASN1c%2Fasn_random_fill.c;h=0000000000000000000000000000000000000000;hp=6bfc2b27d7637514068ea212a0cd3921440a278f;hb=f86662b5b6481f27e18313a36355871f3a947193;hpb=a9f02a2b5886990fd81e64f7c218c5d4844f18a3 diff --git a/e2sim/previous/ASN1c/asn_random_fill.c b/e2sim/previous/ASN1c/asn_random_fill.c deleted file mode 100644 index 6bfc2b2..0000000 --- a/e2sim/previous/ASN1c/asn_random_fill.c +++ /dev/null @@ -1,74 +0,0 @@ -/***************************************************************************** -# * -# Copyright 2019 AT&T Intellectual Property * -# * -# Licensed under the Apache License, Version 2.0 (the "License"); * -# you may not use this file except in compliance with the License. * -# You may obtain a copy of the License at * -# * -# http://www.apache.org/licenses/LICENSE-2.0 * -# * -# Unless required by applicable law or agreed to in writing, software * -# distributed under the License is distributed on an "AS IS" BASIS, * -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * -# See the License for the specific language governing permissions and * -# limitations under the License. * -# * -******************************************************************************/ - -/* - * Copyright (c) 2017 Lev Walkin . - * All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#include -#include -#include - -int -asn_random_fill(const struct asn_TYPE_descriptor_s *td, void **struct_ptr, - size_t length) { - - if(td && td->op->random_fill) { - asn_random_fill_result_t res = - td->op->random_fill(td, struct_ptr, 0, length); - return (res.code == ARFILL_OK) ? 0 : -1; - } else { - return -1; - } -} - -static uintmax_t -asn__intmax_range(intmax_t lb, intmax_t ub) { - assert(lb <= ub); - if((ub < 0) == (lb < 0)) { - return ub - lb; - } else if(lb < 0) { - return 1 + ((uintmax_t)ub + (uintmax_t)-(lb + 1)); - } else { - assert(!"Unreachable"); - return 0; - } -} - -intmax_t -asn_random_between(intmax_t lb, intmax_t rb) { - if(lb == rb) { - return lb; - } else { - const uintmax_t intmax_max = ((~(uintmax_t)0) >> 1); - uintmax_t range = asn__intmax_range(lb, rb); - uintmax_t value = 0; - uintmax_t got_entropy = 0; - - assert(RAND_MAX > 0xffffff); /* Seen 7ffffffd! */ - assert(range < intmax_max); - - for(; got_entropy < range;) { - got_entropy = (got_entropy << 24) | 0xffffff; - value = (value << 24) | (random() % 0xffffff); - } - - return lb + (intmax_t)(value % (range + 1)); - } -}