Esempio n. 1
0
 private void CreateFromParts(IdentifierAuthority identifierAuthority, int[] subAuthorities)
 {
     if (subAuthorities == null)
     {
         throw new ArgumentNullException("subAuthorities");
     }
     if (subAuthorities.Length > (int)SecurityIdentifier.MaxSubAuthorities)
     {
         throw new ArgumentOutOfRangeException("subAuthorities.Length", (object)subAuthorities.Length, Environment.GetResourceString("IdentityReference_InvalidNumberOfSubauthorities", (object)SecurityIdentifier.MaxSubAuthorities));
     }
     if (identifierAuthority < IdentifierAuthority.NullAuthority || identifierAuthority > (IdentifierAuthority)SecurityIdentifier.MaxIdentifierAuthority)
     {
         throw new ArgumentOutOfRangeException("identifierAuthority", (object)identifierAuthority, Environment.GetResourceString("IdentityReference_IdentifierAuthorityTooLarge"));
     }
     this._IdentifierAuthority = identifierAuthority;
     this._SubAuthorities      = new int[subAuthorities.Length];
     subAuthorities.CopyTo((Array)this._SubAuthorities, 0);
     this._BinaryForm    = new byte[8 + 4 * this.SubAuthorityCount];
     this._BinaryForm[0] = SecurityIdentifier.Revision;
     this._BinaryForm[1] = (byte)this.SubAuthorityCount;
     for (byte index = 0; (int)index < 6; ++index)
     {
         this._BinaryForm[2 + (int)index] = (byte)((ulong)this._IdentifierAuthority >> (5 - (int)index) * 8 & (ulong)byte.MaxValue);
     }
     for (byte index1 = 0; (int)index1 < this.SubAuthorityCount; ++index1)
     {
         for (byte index2 = 0; (int)index2 < 4; ++index2)
         {
             this._BinaryForm[8 + 4 * (int)index1 + (int)index2] = (byte)((ulong)this._SubAuthorities[(int)index1] >> (int)index2 * 8);
         }
     }
 }
Esempio n. 2
0
        public SecurityIdentifier(IdentifierAuthority authority, uint[] subs, SidAttributes attributes)
        {
            this.authority = authority;
            subAuthorities = subs;

            Attributes = attributes;
        }
Esempio n. 3
0
        public SecurityIdentifier(IdentifierAuthority authority, int[] subs, SidAttributes attributes)
        {
            this.authority = authority;
            SubAuthorities = subs;

            Attributes = attributes;

            BinaryForm = ToBinaryForm(authority, subs);
        }
Esempio n. 4
0
        public SecurityIdentifier(ReadOnlySpan <byte> binary, SidAttributes attributes = 0)
        {
            BinaryForm = new ReadOnlyMemory <byte>(binary.ToArray());

            authority  = (IdentifierAuthority)binary.Slice(2, 6).AsLong();
            Attributes = attributes;

            SubAuthorities = new int[binary[1]];

            for (var i = 0; i < SubAuthorities.Length; i++)
            {
                SubAuthorities[i] = (int)binary.Slice(8 + (4 * i), 4).AsLong(littleEndian: true);
            }
        }
        public SecurityIdentifier(byte[] binary, SidAttributes attributes = 0)
        {
            BinaryForm = binary;

            var span = new Span <byte>(binary);

            authority  = (IdentifierAuthority)span.Slice(2, 6).AsLong();
            Attributes = attributes;

            SubAuthorities = new int[binary[1]];

            for (var i = 0; i < SubAuthorities.Length; i++)
            {
                SubAuthorities[i] = (int)span.Slice(8 + (4 * i), 4).AsLong(littleEndian: true);
            }
        }
Esempio n. 6
0
        private static byte[] ToBinaryForm(IdentifierAuthority authority, int[] subs)
        {
            var binaryForm = new Memory <byte>(new byte[(1 + 1 + 6) + 4 * subs.Length]);

            binaryForm.Span[0] = 1; // revision
            binaryForm.Span[1] = (byte)subs.Length;

            Endian.ConvertToBigEndian((int)authority, binaryForm.Slice(4, 4));

            for (var i = 0; i < subs.Length; i++)
            {
                Endian.ConvertToLittleEndian(subs[i], binaryForm.Slice(8 + (4 * i), 4));
            }

            return(binaryForm.ToArray());
        }
Esempio n. 7
0
        // Token: 0x06002802 RID: 10242 RVA: 0x000933F0 File Offset: 0x000915F0
        private void CreateFromBinaryForm(byte[] binaryForm, int offset)
        {
            if (binaryForm == null)
            {
                throw new ArgumentNullException("binaryForm");
            }
            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException("offset", offset, Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
            }
            if (binaryForm.Length - offset < SecurityIdentifier.MinBinaryLength)
            {
                throw new ArgumentOutOfRangeException("binaryForm", Environment.GetResourceString("ArgumentOutOfRange_ArrayTooSmall"));
            }
            if (binaryForm[offset] != SecurityIdentifier.Revision)
            {
                throw new ArgumentException(Environment.GetResourceString("IdentityReference_InvalidSidRevision"), "binaryForm");
            }
            if (binaryForm[offset + 1] > SecurityIdentifier.MaxSubAuthorities)
            {
                throw new ArgumentException(Environment.GetResourceString("IdentityReference_InvalidNumberOfSubauthorities", new object[]
                {
                    SecurityIdentifier.MaxSubAuthorities
                }), "binaryForm");
            }
            int num = (int)(8 + 4 * binaryForm[offset + 1]);

            if (binaryForm.Length - offset < num)
            {
                throw new ArgumentException(Environment.GetResourceString("ArgumentOutOfRange_ArrayTooSmall"), "binaryForm");
            }
            IdentifierAuthority identifierAuthority = (IdentifierAuthority)(((ulong)binaryForm[offset + 2] << 40) + ((ulong)binaryForm[offset + 3] << 32) + ((ulong)binaryForm[offset + 4] << 24) + ((ulong)binaryForm[offset + 5] << 16) + ((ulong)binaryForm[offset + 6] << 8) + (ulong)binaryForm[offset + 7]);

            int[] array = new int[(int)binaryForm[offset + 1]];
            for (byte b = 0; b < binaryForm[offset + 1]; b += 1)
            {
                array[(int)b] = (int)binaryForm[offset + 8 + (int)(4 * b)] + ((int)binaryForm[offset + 8 + (int)(4 * b) + 1] << 8) + ((int)binaryForm[offset + 8 + (int)(4 * b) + 2] << 16) + ((int)binaryForm[offset + 8 + (int)(4 * b) + 3] << 24);
            }
            this.CreateFromParts(identifierAuthority, array);
        }
Esempio n. 8
0
        // Token: 0x06002801 RID: 10241 RVA: 0x000932B4 File Offset: 0x000914B4
        private void CreateFromParts(IdentifierAuthority identifierAuthority, int[] subAuthorities)
        {
            if (subAuthorities == null)
            {
                throw new ArgumentNullException("subAuthorities");
            }
            if (subAuthorities.Length > (int)SecurityIdentifier.MaxSubAuthorities)
            {
                throw new ArgumentOutOfRangeException("subAuthorities.Length", subAuthorities.Length, Environment.GetResourceString("IdentityReference_InvalidNumberOfSubauthorities", new object[]
                {
                    SecurityIdentifier.MaxSubAuthorities
                }));
            }
            if (identifierAuthority < IdentifierAuthority.NullAuthority || identifierAuthority > (IdentifierAuthority)SecurityIdentifier.MaxIdentifierAuthority)
            {
                throw new ArgumentOutOfRangeException("identifierAuthority", identifierAuthority, Environment.GetResourceString("IdentityReference_IdentifierAuthorityTooLarge"));
            }
            this._IdentifierAuthority = identifierAuthority;
            this._SubAuthorities      = new int[subAuthorities.Length];
            subAuthorities.CopyTo(this._SubAuthorities, 0);
            this._BinaryForm    = new byte[8 + 4 * this.SubAuthorityCount];
            this._BinaryForm[0] = SecurityIdentifier.Revision;
            this._BinaryForm[1] = (byte)this.SubAuthorityCount;
            byte b;

            for (b = 0; b < 6; b += 1)
            {
                this._BinaryForm[(int)(2 + b)] = (byte)(this._IdentifierAuthority >> (int)((5 - b) * 8 & 63) & (IdentifierAuthority)255L);
            }
            b = 0;
            while ((int)b < this.SubAuthorityCount)
            {
                for (byte b2 = 0; b2 < 4; b2 += 1)
                {
                    this._BinaryForm[(int)(8 + 4 * b + b2)] = (byte)((ulong)((long)this._SubAuthorities[(int)b]) >> (int)(b2 * 8));
                }
                b += 1;
            }
        }
Esempio n. 9
0
        public SecurityIdentifier(byte[] binary, SidAttributes attributes = 0)
        {
            authority  = (IdentifierAuthority)BytesToLong(binary, 2, 5);
            Attributes = attributes;

            var subs = new int[binary[1]];

            for (var i = 0; i < binary[1]; i++)
            {
                subs[i] =
                    (int)(
                        (((uint)binary[8 + 4 * i + 0]) << 0) +
                        (((uint)binary[8 + 4 * i + 1]) << 8) +
                        (((uint)binary[8 + 4 * i + 2]) << 16) +
                        (((uint)binary[8 + 4 * i + 3]) << 24)
                        );
            }

            subAuthorities = new int[subs.Length];

            subs.CopyTo(subAuthorities, 0);
        }
Esempio n. 10
0
        private void CreateFromBinaryForm(byte[] binaryForm, int offset)
        {
            if (binaryForm == null)
            {
                throw new ArgumentNullException("binaryForm");
            }
            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException("offset", (object)offset, Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
            }
            if (binaryForm.Length - offset < SecurityIdentifier.MinBinaryLength)
            {
                throw new ArgumentOutOfRangeException("binaryForm", Environment.GetResourceString("ArgumentOutOfRange_ArrayTooSmall"));
            }
            if ((int)binaryForm[offset] != (int)SecurityIdentifier.Revision)
            {
                throw new ArgumentException(Environment.GetResourceString("IdentityReference_InvalidSidRevision"), "binaryForm");
            }
            if ((int)binaryForm[offset + 1] > (int)SecurityIdentifier.MaxSubAuthorities)
            {
                throw new ArgumentException(Environment.GetResourceString("IdentityReference_InvalidNumberOfSubauthorities", (object)SecurityIdentifier.MaxSubAuthorities), "binaryForm");
            }
            int num = 8 + 4 * (int)binaryForm[offset + 1];

            if (binaryForm.Length - offset < num)
            {
                throw new ArgumentException(Environment.GetResourceString("ArgumentOutOfRange_ArrayTooSmall"), "binaryForm");
            }
            IdentifierAuthority identifierAuthority = (IdentifierAuthority)(((long)binaryForm[offset + 2] << 40) + ((long)binaryForm[offset + 3] << 32) + ((long)binaryForm[offset + 4] << 24) + ((long)binaryForm[offset + 5] << 16) + ((long)binaryForm[offset + 6] << 8) + (long)binaryForm[offset + 7]);

            int[] subAuthorities = new int[(int)binaryForm[offset + 1]];
            for (byte index = 0; (int)index < (int)binaryForm[offset + 1]; ++index)
            {
                subAuthorities[(int)index] = (int)binaryForm[offset + 8 + 4 * (int)index + 0] + ((int)binaryForm[offset + 8 + 4 * (int)index + 1] << 8) + ((int)binaryForm[offset + 8 + 4 * (int)index + 2] << 16) + ((int)binaryForm[offset + 8 + 4 * (int)index + 3] << 24);
            }
            this.CreateFromParts(identifierAuthority, subAuthorities);
        }
Esempio n. 11
0
 internal SecurityIdentifier(IdentifierAuthority identifierAuthority, int[] subAuthorities)
 {
     CreateFromParts(identifierAuthority, subAuthorities);
 }
Esempio n. 12
0
        //
        // Shared constructor logic
        // NOTE: subauthorities are really unsigned integers, but due to CLS
        //       lack of support for unsigned integers the caller must perform
        //       the typecast
        //

        private void CreateFromParts(IdentifierAuthority identifierAuthority, int[] subAuthorities)
        {
            if (subAuthorities == null)
            {
                throw new ArgumentNullException("subAuthorities");
            }

            Contract.EndContractBlock();

            //
            // Check the number of subauthorities passed in
            //

            if (subAuthorities.Length > MaxSubAuthorities)
            {
                throw new ArgumentOutOfRangeException(
                          "subAuthorities.Length",
                          subAuthorities.Length,
                          SR.Format(SR.IdentityReference_InvalidNumberOfSubauthorities, MaxSubAuthorities));
            }

            //
            // Identifier authority is at most 6 bytes long
            //

            if (identifierAuthority < 0 ||
                (long)identifierAuthority > MaxIdentifierAuthority)
            {
                throw new ArgumentOutOfRangeException(
                          "identifierAuthority",
                          identifierAuthority,
                          SR.IdentityReference_IdentifierAuthorityTooLarge);
            }

            //
            // Create a local copy of the data passed in
            //

            _identifierAuthority = identifierAuthority;
            _subAuthorities      = new int[subAuthorities.Length];
            subAuthorities.CopyTo(_subAuthorities, 0);

            //
            // Compute and store the binary form
            //
            // typedef struct _SID {
            //     UCHAR Revision;
            //     UCHAR SubAuthorityCount;
            //     SID_IDENTIFIER_AUTHORITY IdentifierAuthority;
            //     ULONG SubAuthority[ANYSIZE_ARRAY]
            // } SID, *PISID;
            //

            byte i;

            _binaryForm = new byte[1 + 1 + 6 + 4 * this.SubAuthorityCount];

            //
            // First two bytes contain revision and subauthority count
            //

            _binaryForm[0] = Revision;
            _binaryForm[1] = (byte)this.SubAuthorityCount;

            //
            // Identifier authority takes up 6 bytes
            //

            for (i = 0; i < 6; i++)
            {
                _binaryForm[2 + i] = (byte)((((ulong)_identifierAuthority) >> ((5 - i) * 8)) & 0xFF);
            }

            //
            // Subauthorities go last, preserving big-endian representation
            //

            for (i = 0; i < this.SubAuthorityCount; i++)
            {
                byte shift;
                for (shift = 0; shift < 4; shift += 1)
                {
                    _binaryForm[8 + 4 * i + shift] = (byte)(((ulong)_subAuthorities[i]) >> (shift * 8));
                }
            }
        }
Esempio n. 13
0
 internal SecurityIdentifier(IdentifierAuthority identifierAuthority, ReadOnlySpan <int> subAuthorities)
 {
     CreateFromParts(identifierAuthority, subAuthorities);
 }
Esempio n. 14
0
        private void CreateFromBinaryForm(byte[] binaryForm, int offset)
        {
            ArgumentNullException.ThrowIfNull(binaryForm);

            //
            // Negative offsets are not allowed
            //

            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(offset), offset, SR.ArgumentOutOfRange_NeedNonNegNum);
            }

            //
            // At least a minimum-size SID should fit in the buffer
            //

            if (binaryForm.Length - offset < SecurityIdentifier.MinBinaryLength)
            {
                throw new ArgumentOutOfRangeException(nameof(binaryForm), SR.ArgumentOutOfRange_ArrayTooSmall);
            }

            //
            // Extract the elements of a SID
            //

            if (binaryForm[offset] != Revision)
            {
                //
                // Revision is incorrect
                //

                throw new ArgumentException(SR.IdentityReference_InvalidSidRevision, nameof(binaryForm));
            }

            //
            // Insist on the correct number of subauthorities
            //
            int subAuthoritiesLength = binaryForm[offset + 1];

            if (subAuthoritiesLength > MaxSubAuthorities)
            {
                throw new ArgumentException(SR.Format(SR.IdentityReference_InvalidNumberOfSubauthorities, MaxSubAuthorities), nameof(binaryForm));
            }

            //
            // Make sure the buffer is big enough
            //

            int totalLength = 1 + 1 + 6 + 4 * subAuthoritiesLength;

            if (binaryForm.Length - offset < totalLength)
            {
                throw new ArgumentException(SR.ArgumentOutOfRange_ArrayTooSmall, nameof(binaryForm));
            }

            Span <int>          subAuthorities = stackalloc int[MaxSubAuthorities];
            IdentifierAuthority authority      = (IdentifierAuthority)(
                (((long)binaryForm[offset + 2]) << 40) +
                (((long)binaryForm[offset + 3]) << 32) +
                (((long)binaryForm[offset + 4]) << 24) +
                (((long)binaryForm[offset + 5]) << 16) +
                (((long)binaryForm[offset + 6]) << 8) +
                (((long)binaryForm[offset + 7]))
                );

            //
            // Subauthorities are represented in big-endian format
            //

            for (int i = 0; i < subAuthoritiesLength; i++)
            {
                subAuthorities[i] =
                    (int)(
                        (((uint)binaryForm[offset + 8 + 4 * i + 0]) << 0) +
                        (((uint)binaryForm[offset + 8 + 4 * i + 1]) << 8) +
                        (((uint)binaryForm[offset + 8 + 4 * i + 2]) << 16) +
                        (((uint)binaryForm[offset + 8 + 4 * i + 3]) << 24)
                        );
            }

            CreateFromParts(
                authority,
                subAuthorities.Slice(0, subAuthoritiesLength)
                );

            return;
        }
Esempio n. 15
0
        private void CreateFromParts(IdentifierAuthority identifierAuthority, ReadOnlySpan <int> subAuthorities)
        {
            //
            // Check the number of subauthorities passed in
            //
            if (subAuthorities.Length > MaxSubAuthorities)
            {
                throw new ArgumentOutOfRangeException(
                          "subAuthorities.Length",
                          subAuthorities.Length,
                          SR.Format(SR.IdentityReference_InvalidNumberOfSubauthorities, MaxSubAuthorities)
                          );
            }

            //
            // Identifier authority is at most 6 bytes long
            //

            if (identifierAuthority < 0 || (long)identifierAuthority > MaxIdentifierAuthority)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(identifierAuthority),
                          identifierAuthority,
                          SR.IdentityReference_IdentifierAuthorityTooLarge
                          );
            }

            //
            // Create a local copy of the data passed in
            //

            _identifierAuthority = identifierAuthority;
            _subAuthorities      = subAuthorities.ToArray();

            //
            // Compute and store the binary form
            //
            // typedef struct _SID {
            //     UCHAR Revision;
            //     UCHAR SubAuthorityCount;
            //     SID_IDENTIFIER_AUTHORITY IdentifierAuthority;
            //     ULONG SubAuthority[ANYSIZE_ARRAY]
            // } SID, *PISID;
            //

            _binaryForm = new byte[1 + 1 + 6 + 4 * _subAuthorities.Length];

            //
            // First two bytes contain revision and subauthority count
            //

            _binaryForm[0] = Revision;
            _binaryForm[1] = (byte)_subAuthorities.Length;

            //
            // Identifier authority takes up 6 bytes
            //

            for (int i = 0; i < 6; i++)
            {
                _binaryForm[2 + i] = (byte)((((ulong)_identifierAuthority) >> ((5 - i) * 8)) & 0xFF);
            }

            //
            // Subauthorities go last, preserving big-endian representation
            //

            for (int i = 0; i < _subAuthorities.Length; i++)
            {
                for (byte shift = 0; shift < 4; shift += 1)
                {
                    _binaryForm[8 + 4 * i + shift] = unchecked ((byte)(((ulong)_subAuthorities[i]) >> (shift * 8)));
                }
            }
        }
Esempio n. 16
0
 internal SecurityIdentifier(IdentifierAuthority identifierAuthority, int[] subAuthorities)
Esempio n. 17
0
 private void CreateFromParts(IdentifierAuthority identifierAuthority, int[] subAuthorities)