Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infrastructure for Tls #52

Closed
wants to merge 13 commits into from
Prev Previous commit
Next Next commit
clean up reverse
  • Loading branch information
Drawaes committed Jan 16, 2020
commit 59432348be2fb36365968e387d218d9a81164e8c
20 changes: 4 additions & 16 deletions src/Bedrock.Framework.Experimental/Infrastructure/Endianness.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Buffers.Binary;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
Expand Down Expand Up @@ -28,30 +29,17 @@ public static unsafe T Reverse<T>(T value) where T : unmanaged
}
else if (len == 2)
{
var val = Unsafe.Read<ushort>(&value);
val = (ushort)((val >> 8) | (val << 8));
var val = BinaryPrimitives.ReverseEndianness(Unsafe.As<T, ushort>(ref value));
return Unsafe.Read<T>(&val);
}
else if (len == 4)
{
var val = Unsafe.Read<uint>(&value);
val = (val << 24)
| ((val & 0xFF00) << 8)
| ((val & 0xFF0000) >> 8)
| (val >> 24);
var val = BinaryPrimitives.ReverseEndianness(Unsafe.As<T, uint>(ref value));
return Unsafe.Read<T>(&val);
}
else if (len == 8)
{
var val = Unsafe.Read<ulong>(&value);
val = (val << 56)
| ((val & 0xFF00) << 40)
| ((val & 0xFF0000) << 24)
| ((val & 0xFF000000) << 8)
| ((val & 0xFF00000000) >> 8)
| ((val & 0xFF0000000000) >> 24)
| ((val & 0xFF000000000000) >> 40)
| (val >> 56);
var val = BinaryPrimitives.ReverseEndianness(Unsafe.As<T, ulong>(ref value));
return Unsafe.Read<T>(&val);
}
else if (len < 512)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Bedrock.Framework.Experimental.Protocols.Tls.BulkCiphers
{
internal enum KeyMode
{
Encryption = 1,
Decryption = 0,
}
}