Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Unified Diff: third_party/grpc/src/csharp/Grpc.Core/Internal/ChannelCredentialsSafeHandle.cs

Issue 1932353002: Initial checkin of gRPC to third_party/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/grpc/src/csharp/Grpc.Core/Internal/ChannelCredentialsSafeHandle.cs
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/ByteArray.cs b/third_party/grpc/src/csharp/Grpc.Core/Internal/ChannelCredentialsSafeHandle.cs
similarity index 52%
copy from third_party/protobuf/csharp/src/Google.Protobuf/ByteArray.cs
copy to third_party/grpc/src/csharp/Grpc.Core/Internal/ChannelCredentialsSafeHandle.cs
index b19962794b0d052b467fd2007fd09ad1d7fe6d54..65cc2e019fdf8a462b20a5f370f1bed99623c22e 100644
--- a/third_party/protobuf/csharp/src/Google.Protobuf/ByteArray.cs
+++ b/third_party/grpc/src/csharp/Grpc.Core/Internal/ChannelCredentialsSafeHandle.cs
@@ -1,7 +1,6 @@
-#region Copyright notice and license
-// Protocol Buffers - Google's data interchange format
-// Copyright 2008 Google Inc. All rights reserved.
-// https://developers.google.com/protocol-buffers/
+#region Copyright notice and license
+// Copyright 2015-2016, Google Inc.
+// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
@@ -29,51 +28,52 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
-
using System;
+using System.Runtime.InteropServices;
+using System.Threading;
+using System.Threading.Tasks;
-namespace Google.Protobuf
+namespace Grpc.Core.Internal
{
/// <summary>
- /// Provides a utility routine to copy small arrays much more quickly than Buffer.BlockCopy
+ /// grpc_channel_credentials from <c>grpc/grpc_security.h</c>
/// </summary>
- internal static class ByteArray
+ internal class ChannelCredentialsSafeHandle : SafeHandleZeroIsInvalid
{
- /// <summary>
- /// The threshold above which you should use Buffer.BlockCopy rather than ByteArray.Copy
- /// </summary>
- private const int CopyThreshold = 12;
+ static readonly NativeMethods Native = NativeMethods.Get();
+
+ private ChannelCredentialsSafeHandle()
+ {
+ }
+
+ public static ChannelCredentialsSafeHandle CreateNullCredentials()
+ {
+ var creds = new ChannelCredentialsSafeHandle();
+ creds.SetHandle(IntPtr.Zero);
+ return creds;
+ }
- /// <summary>
- /// Determines which copy routine to use based on the number of bytes to be copied.
- /// </summary>
- internal static void Copy(byte[] src, int srcOffset, byte[] dst, int dstOffset, int count)
+ public static ChannelCredentialsSafeHandle CreateSslCredentials(string pemRootCerts, KeyCertificatePair keyCertPair)
{
- if (count > CopyThreshold)
+ if (keyCertPair != null)
{
- Buffer.BlockCopy(src, srcOffset, dst, dstOffset, count);
+ return Native.grpcsharp_ssl_credentials_create(pemRootCerts, keyCertPair.CertificateChain, keyCertPair.PrivateKey);
}
else
{
- int stop = srcOffset + count;
- for (int i = srcOffset; i < stop; i++)
- {
- dst[dstOffset++] = src[i];
- }
+ return Native.grpcsharp_ssl_credentials_create(pemRootCerts, null, null);
}
}
- /// <summary>
- /// Reverses the order of bytes in the array
- /// </summary>
- internal static void Reverse(byte[] bytes)
+ public static ChannelCredentialsSafeHandle CreateComposite(ChannelCredentialsSafeHandle channelCreds, CallCredentialsSafeHandle callCreds)
{
- for (int first = 0, last = bytes.Length - 1; first < last; first++, last--)
- {
- byte temp = bytes[first];
- bytes[first] = bytes[last];
- bytes[last] = temp;
- }
+ return Native.grpcsharp_composite_channel_credentials_create(channelCreds, callCreds);
+ }
+
+ protected override bool ReleaseHandle()
+ {
+ Native.grpcsharp_channel_credentials_release(handle);
+ return true;
}
}
-}
+}

Powered by Google App Engine
This is Rietveld 408576698