Example #1
0
        public string Decrypt(string message)
        {
            Initialize();
            AssertUtils.AssertNotNull(message);

            return(Charset.GetString(Encryptor.Decrypt(BaseEncoder.Decode(message))));
        }
Example #2
0
        protected override System.Array DecodeSlice(byte[] slice)
        {
            Array      sliceData     = null;
            int        slicePosition = 0;
            int        type          = 0;
            DbDataType dbType        = DbDataType.Array;
            Type       systemType    = this.GetSystemType();
            Charset    charset       = this.db.Charset;

            int[] lengths     = new int[this.Descriptor.Dimensions];
            int[] lowerBounds = new int[this.Descriptor.Dimensions];

            // Get upper and lower bounds of each dimension
            for (int i = 0; i < this.Descriptor.Dimensions; i++)
            {
                lowerBounds[i] = this.Descriptor.Bounds[i].LowerBound;
                lengths[i]     = this.Descriptor.Bounds[i].UpperBound;

                if (lowerBounds[i] == 0)
                {
                    lengths[i]++;
                }
            }

            // Create slice	arrays
            sliceData = Array.CreateInstance(systemType, lengths, lowerBounds);

            Array tempData = Array.CreateInstance(systemType, sliceData.Length);

            // Infer data types
            type   = TypeHelper.GetFbType(this.Descriptor.DataType);
            dbType = TypeHelper.GetDbDataType(this.Descriptor.DataType, 0, this.Descriptor.Scale);

            int itemLength = this.Descriptor.Length;

            for (int i = 0; i < tempData.Length; i++)
            {
                if (slicePosition >= slice.Length)
                {
                    break;
                }

                switch (dbType)
                {
                case DbDataType.Char:
                    tempData.SetValue(charset.GetString(slice, slicePosition, itemLength), i);
                    break;

                case DbDataType.VarChar:
                {
                    int index = slicePosition;
                    int count = 0;
                    while (slice[index++] != 0)
                    {
                        count++;
                    }
                    tempData.SetValue(charset.GetString(slice, slicePosition, count), i);

                    slicePosition += 2;
                }
                break;

                case DbDataType.SmallInt:
                    tempData.SetValue(BitConverter.ToInt16(slice, slicePosition), i);
                    break;

                case DbDataType.Integer:
                    tempData.SetValue(BitConverter.ToInt32(slice, slicePosition), i);
                    break;

                case DbDataType.BigInt:
                    tempData.SetValue(BitConverter.ToInt64(slice, slicePosition), i);
                    break;

                case DbDataType.Decimal:
                case DbDataType.Numeric:
                {
                    object evalue = null;

                    switch (type)
                    {
                    case IscCodes.SQL_SHORT:
                        evalue = BitConverter.ToInt16(slice, slicePosition);
                        break;

                    case IscCodes.SQL_LONG:
                        evalue = BitConverter.ToInt32(slice, slicePosition);
                        break;

                    case IscCodes.SQL_QUAD:
                    case IscCodes.SQL_INT64:
                        evalue = BitConverter.ToInt64(slice, slicePosition);
                        break;
                    }

                    decimal dvalue = TypeDecoder.DecodeDecimal(evalue, this.Descriptor.Scale, type);

                    tempData.SetValue(dvalue, i);
                }
                break;

                case DbDataType.Double:
                    tempData.SetValue(BitConverter.ToDouble(slice, slicePosition), i);
                    break;

                case DbDataType.Float:
                    tempData.SetValue(BitConverter.ToSingle(slice, slicePosition), i);
                    break;

                case DbDataType.Date:
                {
                    int idate = BitConverter.ToInt32(slice, slicePosition);

                    DateTime date = TypeDecoder.DecodeDate(idate);

                    tempData.SetValue(date, i);
                }
                break;

                case DbDataType.Time:
                {
                    int itime = BitConverter.ToInt32(slice, slicePosition);

                    TimeSpan time = TypeDecoder.DecodeTime(itime);

                    tempData.SetValue(time, i);
                }
                break;

                case DbDataType.TimeStamp:
                {
                    int idate = BitConverter.ToInt32(slice, slicePosition);
                    int itime = BitConverter.ToInt32(slice, slicePosition + 4);

                    DateTime date = TypeDecoder.DecodeDate(idate);
                    TimeSpan time = TypeDecoder.DecodeTime(itime);

                    DateTime timestamp = new System.DateTime(
                        date.Year, date.Month, date.Day,
                        time.Hours, time.Minutes, time.Seconds, time.Milliseconds);

                    tempData.SetValue(timestamp, i);
                }
                break;
                }

                slicePosition += itemLength;
            }

            if (systemType.IsPrimitive)
            {
                // For primitive types we can use System.Buffer	to copy	generated data to destination array
                Buffer.BlockCopy(tempData, 0, sliceData, 0, Buffer.ByteLength(tempData));
            }
            else
            {
                sliceData = tempData;
            }

            return(sliceData);
        }
Example #3
0
        public async ValueTask <string> ReadStringAsync(Charset charset, int length, CancellationToken cancellationToken = default)
        {
            var buffer = await ReadOpaqueAsync(length, cancellationToken).ConfigureAwait(false);

            return(charset.GetString(buffer, 0, buffer.Length));
        }
Example #4
0
        public string ReadString(Charset charset, int length)
        {
            var buffer = ReadOpaque(length);

            return(charset.GetString(buffer, 0, buffer.Length));
        }
 private static string GetString(Charset charset, byte[] buffer, short bufferLength)
 {
     return(charset.GetString(buffer, 0, bufferLength));
 }
        private static string GetString(Charset charset, byte[] buffer)
        {
            var value = charset.GetString(buffer);

            return(value.TrimEnd('\0', ' '));
        }
Example #7
0
        public string ReadString(Charset charset, int length)
        {
            var buf = InternalReadBuffer(length, opaque: true);

            return(charset.GetString(buf, 0, length));
        }
        public async Task <string> ReadString(Charset charset, int length, AsyncWrappingCommonArgs async)
        {
            var buffer = await ReadOpaque(length, async).ConfigureAwait(false);

            return(charset.GetString(buffer, 0, buffer.Length));
        }
Example #9
0
    public string ReadString()
    {
        var buffer = Read();

        return(_charset.GetString(buffer, 0, buffer.Length));
    }
        public static IscException ParseStatusVector(IntPtr[] statusVector, Charset charset)
        {
            IscException exception = null;
            bool         eof       = false;

            for (int i = 0; i < statusVector.Length;)
            {
                IntPtr arg = statusVector[i++];

                switch (arg.AsInt())
                {
                case IscCodes.isc_arg_gds:
                default:
                    IntPtr er = statusVector[i++];
                    if (er != IntPtr.Zero)
                    {
                        if (exception == null)
                        {
                            exception = IscException.ForBuilding();
                        }
                        exception.Errors.Add(new IscError(arg.AsInt(), er.AsInt()));
                    }
                    break;

                case IscCodes.isc_arg_end:
                    exception?.BuildExceptionData();
                    eof = true;
                    break;

                case IscCodes.isc_arg_interpreted:
                case IscCodes.isc_arg_string:
                {
                    IntPtr ptr       = statusVector[i++];
                    string s         = Marshal.PtrToStringAnsi(ptr);
                    string arg_value = charset.GetString(Encoding2.Default.GetBytes(s));
                    exception.Errors.Add(new IscError(arg.AsInt(), arg_value));
                }
                break;

                case IscCodes.isc_arg_cstring:
                {
                    i++;

                    IntPtr ptr       = statusVector[i++];
                    string s         = Marshal.PtrToStringAnsi(ptr);
                    string arg_value = charset.GetString(Encoding2.Default.GetBytes(s));
                    exception.Errors.Add(new IscError(arg.AsInt(), arg_value));
                }
                break;

                case IscCodes.isc_arg_win32:
                case IscCodes.isc_arg_number:
                    exception.Errors.Add(new IscError(arg.AsInt(), statusVector[i++].AsInt()));
                    break;

                case IscCodes.isc_arg_sql_state:
                {
                    IntPtr ptr       = statusVector[i++];
                    string s         = Marshal.PtrToStringAnsi(ptr);
                    string arg_value = charset.GetString(Encoding2.Default.GetBytes(s));
                    exception.Errors.Add(new IscError(arg.AsInt(), arg_value));
                }
                break;
                }

                if (eof)
                {
                    break;
                }
            }

            return(exception);
        }
Example #11
0
        public string ReadString(Charset charset, int length)
        {
            byte[] buffer = this.ReadOpaque(length);

            return(charset.GetString(buffer, 0, buffer.Length));
        }
    public void SetValue(byte[] buffer)
    {
        if (buffer == null || NullFlag == -1)
        {
            DbValue.SetValue(DBNull.Value);
        }
        else
        {
            switch (SqlType)
            {
            case IscCodes.SQL_TEXT:
            case IscCodes.SQL_VARYING:
                if (DbDataType == DbDataType.Guid)
                {
                    DbValue.SetValue(TypeDecoder.DecodeGuid(buffer));
                }
                else
                {
                    if (Charset.IsOctetsCharset)
                    {
                        DbValue.SetValue(buffer);
                    }
                    else
                    {
                        var s = Charset.GetString(buffer, 0, buffer.Length);

                        if ((Length % Charset.BytesPerCharacter) == 0 &&
                            s.Length > CharCount)
                        {
                            s = s.Substring(0, CharCount);
                        }

                        DbValue.SetValue(s);
                    }
                }
                break;

            case IscCodes.SQL_SHORT:
                if (_numericScale < 0)
                {
                    DbValue.SetValue(TypeDecoder.DecodeDecimal(BitConverter.ToInt16(buffer, 0), _numericScale, _dataType));
                }
                else
                {
                    DbValue.SetValue(BitConverter.ToInt16(buffer, 0));
                }
                break;

            case IscCodes.SQL_LONG:
                if (_numericScale < 0)
                {
                    DbValue.SetValue(TypeDecoder.DecodeDecimal(BitConverter.ToInt32(buffer, 0), _numericScale, _dataType));
                }
                else
                {
                    DbValue.SetValue(BitConverter.ToInt32(buffer, 0));
                }
                break;

            case IscCodes.SQL_FLOAT:
                DbValue.SetValue(BitConverter.ToSingle(buffer, 0));
                break;

            case IscCodes.SQL_DOUBLE:
            case IscCodes.SQL_D_FLOAT:
                DbValue.SetValue(BitConverter.ToDouble(buffer, 0));
                break;

            case IscCodes.SQL_QUAD:
            case IscCodes.SQL_INT64:
            case IscCodes.SQL_BLOB:
            case IscCodes.SQL_ARRAY:
                if (_numericScale < 0)
                {
                    DbValue.SetValue(TypeDecoder.DecodeDecimal(BitConverter.ToInt64(buffer, 0), _numericScale, _dataType));
                }
                else
                {
                    DbValue.SetValue(BitConverter.ToInt64(buffer, 0));
                }
                break;

            case IscCodes.SQL_TIMESTAMP:
            {
                var date = TypeDecoder.DecodeDate(BitConverter.ToInt32(buffer, 0));
                var time = TypeDecoder.DecodeTime(BitConverter.ToInt32(buffer, 4));
                DbValue.SetValue(date.Add(time));
                break;
            }

            case IscCodes.SQL_TYPE_TIME:
                DbValue.SetValue(TypeDecoder.DecodeTime(BitConverter.ToInt32(buffer, 0)));
                break;

            case IscCodes.SQL_TYPE_DATE:
                DbValue.SetValue(TypeDecoder.DecodeDate(BitConverter.ToInt32(buffer, 0)));
                break;

            case IscCodes.SQL_BOOLEAN:
                DbValue.SetValue(TypeDecoder.DecodeBoolean(buffer));
                break;

            case IscCodes.SQL_TIMESTAMP_TZ:
            {
                var date = TypeDecoder.DecodeDate(BitConverter.ToInt32(buffer, 0));
                var time = TypeDecoder.DecodeTime(BitConverter.ToInt32(buffer, 4));
                var tzId = BitConverter.ToUInt16(buffer, 8);
                var dt   = DateTime.SpecifyKind(date.Add(time), DateTimeKind.Utc);
                DbValue.SetValue(TypeHelper.CreateZonedDateTime(dt, tzId, null));
                break;
            }

            case IscCodes.SQL_TIMESTAMP_TZ_EX:
            {
                var date   = TypeDecoder.DecodeDate(BitConverter.ToInt32(buffer, 0));
                var time   = TypeDecoder.DecodeTime(BitConverter.ToInt32(buffer, 4));
                var tzId   = BitConverter.ToUInt16(buffer, 8);
                var offset = BitConverter.ToInt16(buffer, 10);
                var dt     = DateTime.SpecifyKind(date.Add(time), DateTimeKind.Utc);
                DbValue.SetValue(TypeHelper.CreateZonedDateTime(dt, tzId, offset));
                break;
            }

            case IscCodes.SQL_TIME_TZ:
            {
                var time = TypeDecoder.DecodeTime(BitConverter.ToInt32(buffer, 0));
                var tzId = BitConverter.ToUInt16(buffer, 4);
                DbValue.SetValue(TypeHelper.CreateZonedTime(time, tzId, null));
                break;
            }

            case IscCodes.SQL_TIME_TZ_EX:
            {
                var time   = TypeDecoder.DecodeTime(BitConverter.ToInt32(buffer, 0));
                var tzId   = BitConverter.ToUInt16(buffer, 4);
                var offset = BitConverter.ToInt16(buffer, 6);
                DbValue.SetValue(TypeHelper.CreateZonedTime(time, tzId, offset));
                break;
            }

            case IscCodes.SQL_DEC16:
                DbValue.SetValue(DecimalCodec.DecFloat16.ParseBytes(buffer));
                break;

            case IscCodes.SQL_DEC34:
                DbValue.SetValue(DecimalCodec.DecFloat34.ParseBytes(buffer));
                break;

            case IscCodes.SQL_INT128:
                if (_numericScale < 0)
                {
                    DbValue.SetValue(TypeDecoder.DecodeDecimal(Int128Helper.GetInt128(buffer), _numericScale, _dataType));
                }
                else
                {
                    DbValue.SetValue(Int128Helper.GetInt128(buffer));
                }
                break;

            default:
                throw TypeHelper.InvalidDataType(SqlType);
            }
        }
    }
        private string GetString(Charset charset, byte[] buffer)
        {
            string value = charset.GetString(buffer);

            return(value.Replace('\0', ' ').Trim());
        }