Sha256: 5da34966008d994cc01a2d81ac8a4af028f8a68d1f9810e445f15ff9cd588b29
Contents?: true
Size: 1.63 KB
Versions: 5
Compression:
Stored size: 1.63 KB
Contents
/* * Copyright 2020–present MongoDB, Inc. * * 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. */ using System; using System.Security.Cryptography; namespace MongoDB.Libmongocrypt { internal static class SecureRandomCallback { public static bool GenerateRandom( IntPtr ctx, IntPtr @out, uint count, IntPtr statusPtr) { using (var outBinary = new Binary(BinarySafeHandle.FromIntPtr(@out))) using (var status = new Status(StatusSafeHandle.FromIntPtr(statusPtr))) { try { using (var randomNumberGenerator = RandomNumberGenerator.Create()) { var bytes = new byte[count]; randomNumberGenerator.GetBytes(bytes); outBinary.WriteBytes(bytes); return true; } } catch (Exception e) { status.SetStatus(1, e.Message); return false; } } } } }
Version data entries
5 entries across 5 versions & 1 rubygems