예제 #1
0
        public string Digest(string message)
        {
            Initialize();
            AssertUtils.AssertNotNull(message);

            return(BaseEncoder.Encode(Digester.Digest(Charset.GetBytes(message))));
        }
        private static byte[] GetStringBuffer(Charset charset, string value)
        {
            var buffer = new byte[32];

            charset.GetBytes(value, 0, value.Length, buffer, 0);
            return(buffer);
        }
예제 #3
0
        public bool Verify(string message, string digested)
        {
            Initialize();
            AssertUtils.AssertNotNull(message);
            AssertUtils.AssertNotNull(digested);

            return(Digester.Verify(Charset.GetBytes(message), BaseEncoder.Decode(digested)));
        }
예제 #4
0
        public void Write(string value, Charset charset)
        {
            var count = charset.GetBytesCount(value);

            Write(count);
            var buff = InternalGetBuffer(count);

            charset.GetBytes(value, 0, value.Length, buff, 0);
            Write(buff, 0, count);
            WritePadding(count);
        }
예제 #5
0
        /// <summary>
        /// Gets the salt for user passwords.
        /// </summary>
        /// <returns>The salt.</returns>
        public static byte[] GetUserPasswordSalt()
        {
            if (IsMyAssembly(Assembly.GetCallingAssembly()) == false)
            {
                return(null);
            }

            string salt = null;

            try
            {
                salt = GetAppSettingValue("UserPasswordSalt");

                return(salt == null ? null : Charset.GetBytes(salt));
            }
            finally
            {
                salt = null;
            }
        }
예제 #6
0
        /// <summary>
        /// Gets the system password.
        /// </summary>
        /// <returns>The password.</returns>
        public static byte[] GetPassword()
        {
            if (IsMyAssembly(Assembly.GetCallingAssembly()) == false)
            {
                return(null);
            }

            string pwd = null;

            try
            {
                pwd = GetAppSettingValue("Password");

                return(pwd == null ? null : Charset.GetBytes(pwd));
            }
            finally
            {
                pwd = null;
            }
        }
예제 #7
0
        private byte[] EncodeSlice(ArrayDesc desc, Array sourceArray, int length)
        {
            BinaryWriter writer  = new BinaryWriter(new MemoryStream());
            Charset      charset = this.db.Charset;
            DbDataType   dbType  = DbDataType.Array;
            int          subType = (this.Descriptor.Scale < 0) ? 2 : 0;
            int          type    = 0;

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

            foreach (object source in sourceArray)
            {
                switch (dbType)
                {
                case DbDataType.Char:
                {
                    string value  = source != null ? (string)source : string.Empty;
                    byte[] buffer = charset.GetBytes(value);

                    writer.Write(buffer);

                    if (desc.Length > buffer.Length)
                    {
                        for (int j = buffer.Length; j < desc.Length; j++)
                        {
                            writer.Write((byte)32);
                        }
                    }
                }
                break;

                case DbDataType.VarChar:
                {
                    string value = source != null ? (string)source : string.Empty;

                    byte[] buffer = charset.GetBytes(value);
                    writer.Write(buffer);

                    if (desc.Length > buffer.Length)
                    {
                        for (int j = buffer.Length; j < desc.Length; j++)
                        {
                            writer.Write((byte)0);
                        }
                    }
                    writer.Write((short)0);
                }
                break;

                case DbDataType.SmallInt:
                    writer.Write((short)source);
                    break;

                case DbDataType.Integer:
                    writer.Write((int)source);
                    break;

                case DbDataType.BigInt:
                    writer.Write((long)source);
                    break;

                case DbDataType.Float:
                    writer.Write((float)source);
                    break;

                case DbDataType.Double:
                    writer.Write((double)source);
                    break;

                case DbDataType.Numeric:
                case DbDataType.Decimal:
                {
                    object numeric = TypeEncoder.EncodeDecimal((decimal)source, desc.Scale, type);

                    switch (type)
                    {
                    case IscCodes.SQL_SHORT:
                        writer.Write((short)numeric);
                        break;

                    case IscCodes.SQL_LONG:
                        writer.Write((int)numeric);
                        break;

                    case IscCodes.SQL_QUAD:
                    case IscCodes.SQL_INT64:
                        writer.Write((long)numeric);
                        break;
                    }
                }
                break;

                case DbDataType.Date:
                    writer.Write(TypeEncoder.EncodeDate(Convert.ToDateTime(source, CultureInfo.CurrentCulture.DateTimeFormat)));
                    break;

                case DbDataType.Time:
                    writer.Write(TypeEncoder.EncodeTime((TimeSpan)source));
                    break;

                case DbDataType.TimeStamp:
                    var dt = Convert.ToDateTime(source, CultureInfo.CurrentCulture.DateTimeFormat);
                    writer.Write(TypeEncoder.EncodeDate(dt));
                    writer.Write(TypeEncoder.EncodeTime(TypeHelper.DateTimeToTimeSpan(dt)));
                    break;

                default:
                    throw new NotSupportedException("Unknown data type");
                }
            }

            return(((MemoryStream)writer.BaseStream).ToArray());
        }
예제 #8
0
        private byte[] EncodeSliceArray(Array sourceArray)
        {
            DbDataType dbType  = DbDataType.Array;
            Charset    charset = _database.Charset;
            int        subType = (Descriptor.Scale < 0) ? 2 : 0;
            int        type    = 0;

            using (XdrStream xdr = new XdrStream(_database.Charset))
            {
                type   = TypeHelper.GetSqlTypeFromBlrType(Descriptor.DataType);
                dbType = TypeHelper.GetDbDataTypeFromBlrType(Descriptor.DataType, subType, Descriptor.Scale);

                foreach (object source in sourceArray)
                {
                    switch (dbType)
                    {
                    case DbDataType.Char:
                        byte[] buffer = charset.GetBytes(source.ToString());
                        xdr.WriteOpaque(buffer, Descriptor.Length);
                        break;

                    case DbDataType.VarChar:
                        xdr.Write((string)source);
                        break;

                    case DbDataType.SmallInt:
                        xdr.Write((short)source);
                        break;

                    case DbDataType.Integer:
                        xdr.Write((int)source);
                        break;

                    case DbDataType.BigInt:
                        xdr.Write((long)source);
                        break;

                    case DbDataType.Decimal:
                    case DbDataType.Numeric:
                        xdr.Write((decimal)source, type, Descriptor.Scale);
                        break;

                    case DbDataType.Float:
                        xdr.Write((float)source);
                        break;

                    case DbDataType.Double:
                        xdr.Write((double)source);
                        break;

                    case DbDataType.Date:
                        xdr.WriteDate(Convert.ToDateTime(source, CultureInfo.CurrentCulture.DateTimeFormat));
                        break;

                    case DbDataType.Time:
                        xdr.WriteTime((TimeSpan)source);
                        break;

                    case DbDataType.TimeStamp:
                        xdr.Write(Convert.ToDateTime(source, CultureInfo.CurrentCulture.DateTimeFormat));
                        break;

                    default:
                        throw TypeHelper.InvalidDataType((int)dbType);
                    }
                }

                return(xdr.ToArray());
            }
        }
예제 #9
0
        public void Write(string value)
        {
            var buffer = _charset.GetBytes(value);

            WriteBuffer(buffer, buffer.Length);
        }
        public Task Write(string value, AsyncWrappingCommonArgs async)
        {
            var buffer = _charset.GetBytes(value);

            return(WriteBuffer(buffer, buffer.Length, async));
        }
예제 #11
0
 public void Write(string data)
 {
     Write(_charset.GetBytes(data));
 }
예제 #12
0
        public void Write(DbField param)
        {
            Charset innerCharset = (this.charset.Name != "NONE") ? this.charset : param.Charset;

            param.FixNull();

            try
            {
                switch (param.DbDataType)
                {
                case DbDataType.Char:
                {
                    string svalue = param.DbValue.GetString();

                    if ((param.Length % param.Charset.BytesPerCharacter) == 0 &&
                        svalue.Length > param.CharCount)
                    {
                        throw new IscException(335544321);
                    }

                    this.WriteOpaque(innerCharset.GetBytes(svalue), param.Length);
                }
                break;

                case DbDataType.VarChar:
                {
                    string svalue = param.DbValue.GetString().TrimEnd();

                    if ((param.Length % param.Charset.BytesPerCharacter) == 0 &&
                        svalue.Length > param.CharCount)
                    {
                        throw new IscException(335544321);
                    }

                    byte[] data = innerCharset.GetBytes(svalue);

                    this.WriteBuffer(data, data.Length);
                }
                break;

                case DbDataType.SmallInt:
                    this.Write(param.DbValue.GetInt16());
                    break;

                case DbDataType.Integer:
                    this.Write(param.DbValue.GetInt32());
                    break;

                case DbDataType.BigInt:
                case DbDataType.Array:
                case DbDataType.Binary:
                case DbDataType.Text:
                    this.Write(param.DbValue.GetInt64());
                    break;

                case DbDataType.Decimal:
                case DbDataType.Numeric:
                    this.Write(
                        param.DbValue.GetDecimal(),
                        param.DataType,
                        param.NumericScale);
                    break;

                case DbDataType.Float:
                    this.Write(param.DbValue.GetFloat());
                    break;

                case DbDataType.Guid:
                    this.WriteOpaque(param.DbValue.GetGuid().ToByteArray());
                    break;

                case DbDataType.Double:
                    this.Write(param.DbValue.GetDouble());
                    break;

                case DbDataType.Date:
                    this.Write(param.DbValue.EncodeDate());
                    break;

                case DbDataType.Time:
                    this.Write(param.DbValue.EncodeTime());
                    break;

                case DbDataType.TimeStamp:
                    this.Write(param.DbValue.EncodeDate());
                    this.Write(param.DbValue.EncodeTime());
                    break;

                default:
                    throw new IscException("Unknown sql data type: " + param.DataType);
                }

                this.Write(param.NullFlag);
            }
            catch (IOException)
            {
                throw new IscException(IscCodes.isc_net_write_err);
            }
        }
예제 #13
0
        private byte[] EncodeSliceArray(Array sourceArray)
        {
            IEnumerator i       = sourceArray.GetEnumerator();
            DbDataType  dbType  = DbDataType.Array;
            Charset     charset = this.db.Charset;
            XdrStream   xdr     = new XdrStream(this.db.Charset);
            int         type    = 0;
            int         subtype = (this.Descriptor.Scale < 0) ? 2 : 0;

            type   = TypeHelper.GetFbType(this.Descriptor.DataType);
            dbType = TypeHelper.GetDbDataType(this.Descriptor.DataType, subtype, this.Descriptor.Scale);

            while (i.MoveNext())
            {
                switch (dbType)
                {
                case DbDataType.Char:
                    byte[] buffer = charset.GetBytes(i.Current.ToString());
                    xdr.WriteOpaque(buffer, this.Descriptor.Length);
                    break;

                case DbDataType.VarChar:
                    xdr.Write((string)i.Current);
                    break;

                case DbDataType.SmallInt:
                    xdr.Write((short)i.Current);
                    break;

                case DbDataType.Integer:
                    xdr.Write((int)i.Current);
                    break;

                case DbDataType.BigInt:
                    xdr.Write((long)i.Current);
                    break;

                case DbDataType.Decimal:
                case DbDataType.Numeric:
                    xdr.Write((decimal)i.Current, type, this.Descriptor.Scale);
                    break;

                case DbDataType.Float:
                    xdr.Write((float)i.Current);
                    break;

                case DbDataType.Double:
                    xdr.Write((double)i.Current);
                    break;

                case DbDataType.Date:
                    xdr.WriteDate(Convert.ToDateTime(i.Current, CultureInfo.CurrentCulture.DateTimeFormat));
                    break;

                case DbDataType.Time:
                    xdr.WriteTime(Convert.ToDateTime(i.Current, CultureInfo.CurrentCulture.DateTimeFormat));
                    break;

                case DbDataType.TimeStamp:
                    xdr.Write(Convert.ToDateTime(i.Current, CultureInfo.CurrentCulture.DateTimeFormat));
                    break;

                default:
                    throw new NotSupportedException("Unknown data type");
                }
            }

            return(xdr.ToArray());
        }
예제 #14
0
 public void Write(string data)
 {
     Content.WriteBytes(Charset.GetBytes(data));
 }