ToSByteArray() private method

private ToSByteArray ( byte byteArray ) : sbyte[]
byteArray byte
return sbyte[]
Ejemplo n.º 1
0
        /// <summary>
        /// Constructs an extended operation object for receiving all updates from
        /// another directory server for a specific replica.
        ///
        /// </summary>
        /// <param name="partitionRoot">  The distinguished name of the replica
        /// that will be updated.
        ///
        /// </param>
        /// <param name="toServerDN">     The distinguished name of the server holding the
        /// replica to be updated.
        ///
        /// </param>
        /// <param name="fromServerDN">   The distinguished name of the server from which
        /// updates are sent.
        ///
        /// </param>
        /// <exception> LdapException A general exception which includes an error message
        /// and an Ldap error code.
        /// </exception>
        public ReceiveAllUpdatesRequest(String partitionRoot, String toServerDN, String fromServerDN) : base(ReplicationConstants.RECEIVE_ALL_UPDATES_REQ, null)
        {
            try
            {
                if (((object)partitionRoot == null) || ((object)toServerDN == null) || ((object)fromServerDN == null))
                {
                    throw new ArgumentException(ExceptionMessages.PARAM_ERROR);
                }

                System.IO.MemoryStream encodedData = new System.IO.MemoryStream();
                LBEREncoder            encoder     = new LBEREncoder();

                Asn1OctetString asn1_partitionRoot = new Asn1OctetString(partitionRoot);
                Asn1OctetString asn1_toServerDN    = new Asn1OctetString(toServerDN);
                Asn1OctetString asn1_fromServerDN  = new Asn1OctetString(fromServerDN);

                asn1_partitionRoot.encode(encoder, encodedData);
                asn1_toServerDN.encode(encoder, encodedData);
                asn1_fromServerDN.encode(encoder, encodedData);

                setValue(SupportClass.ToSByteArray(encodedData.ToArray()));
            }
            catch (System.IO.IOException ioe)
            {
                throw new LdapException(ExceptionMessages.ENCODING_ERROR, LdapException.ENCODING_ERROR, (String)null);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Constructs a new extended operation object for adding a replica to the
        ///     specified server.
        /// </summary>
        /// <param name="dn">
        ///     The distinguished name of the replica's partition root.
        /// </param>
        /// <param name="serverDN">
        ///     The server on which the new replica will be added.
        /// </param>
        /// <param name="replicaType">
        ///     The type of replica to add. The replica
        ///     types are defined in the ReplicationConstants class.
        /// </param>
        /// <param name="flags">
        ///     Specifies whether all servers in the replica ring must be up
        ///     before proceeding. When set to zero, the status of the servers is not
        ///     checked. When set to Ldap_ENSURE_SERVERS_UP, all servers must be up for the
        ///     operation to proceed.
        /// </param>
        /// <exception>
        ///     LdapException A general exception which includes an error message
        ///     and an Ldap error code.
        /// </exception>
        /// <seealso cref="ReplicationConstants.Ldap_RT_MASTER">
        /// </seealso>
        /// <seealso cref="ReplicationConstants.Ldap_RT_SECONDARY">
        /// </seealso>
        /// <seealso cref="ReplicationConstants.Ldap_RT_READONLY">
        /// </seealso>
        /// <seealso cref="ReplicationConstants.Ldap_RT_SUBREF">
        /// </seealso>
        /// <seealso cref="ReplicationConstants.Ldap_RT_SPARSE_WRITE">
        /// </seealso>
        /// <seealso cref="ReplicationConstants.Ldap_RT_SPARSE_READ">
        /// </seealso>
        public AddReplicaRequest(string dn, string serverDN, int replicaType, int flags)
            : base(ReplicationConstants.ADD_REPLICA_REQ, null)
        {
            try
            {
                if ((object)dn == null || (object)serverDN == null)
                {
                    throw new ArgumentException(ExceptionMessages.PARAM_ERROR);
                }

                var encodedData = new MemoryStream();
                var encoder     = new LBEREncoder();

                var asn1_flags       = new Asn1Integer(flags);
                var asn1_replicaType = new Asn1Integer(replicaType);
                var asn1_serverDN    = new Asn1OctetString(serverDN);
                var asn1_dn          = new Asn1OctetString(dn);

                asn1_flags.encode(encoder, encodedData);
                asn1_replicaType.encode(encoder, encodedData);
                asn1_serverDN.encode(encoder, encodedData);
                asn1_dn.encode(encoder, encodedData);

                setValue(SupportClass.ToSByteArray(encodedData.ToArray()));
            }
            catch (IOException ioe)
            {
                throw new LdapException(ExceptionMessages.ENCODING_ERROR, LdapException.ENCODING_ERROR, null, ioe);
            }
        }
Ejemplo n.º 3
0
        /// <summary> Converts the image to a java.awt.image.BufferedImage object.
        /// The type of the buffered image must be either BufferedImage.TYPE_4BYTE_ABGR
        /// or BufferedImage.TYPE_3BYTE_BGR.
        ///
        /// </summary>
        /// <param name="type">type of the image
        /// </param>
        /// <returns> the BufferedImage object
        /// </returns>
        public virtual System.Drawing.Bitmap convertToBufferedImage(int type)
        {
            int pixelFormat;

            if (type == (int)System.Drawing.Imaging.PixelFormat.Format24bppRgb)
            {
                pixelFormat = Format.R8G8B8;
            }
            else if (type == (int)System.Drawing.Imaging.PixelFormat.Format32bppArgb)
            {
                pixelFormat = Format.R8G8B8A8;
            }
            else
            {
                throw new System.ArgumentException();
            }


            System.Drawing.Bitmap  image = new System.Drawing.Bitmap(width, height, (System.Drawing.Imaging.PixelFormat)type);
            System.IO.MemoryStream tempDataBuffer;
            tempDataBuffer = new System.IO.MemoryStream();
            //UPGRADE_TODO: Method 'java.awt.image.Raster.getDataBuffer' was converted to 'System.Drawing.Bitmap' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_javaawtimageRastergetDataBuffer_3"'
            image.Save(tempDataBuffer, System.Drawing.Imaging.ImageFormat.Bmp);
            System.Collections.ArrayList buffer     = new System.Collections.ArrayList(tempDataBuffer.ToArray());
            System.Collections.ArrayList byteBuffer = (System.Collections.ArrayList)buffer;

            read(0, 0, width, height, SupportClass.ToSByteArray((byte[])byteBuffer[0]), pixelFormat);
            return(image);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Constructs an extended operation object for merging partitions.
        /// </summary>
        /// <param name="dn">
        ///     The distinguished name of the child partition's root.
        /// </param>
        /// <param name="flags">
        ///     Determines whether all servers in the replica ring must
        ///     be up before proceeding. When set to zero, the status of
        ///     the servers is not checked. When set to
        ///     Ldap_ENSURE_SERVERS_UP, all servers must be up for the
        ///     operation to proceed.
        /// </param>
        /// <exception>
        ///     LdapException A general exception which includes an error
        ///     message and an Ldap error code.
        /// </exception>
        public MergePartitionsRequest(string dn, int flags) : base(ReplicationConstants.MERGE_NAMING_CONTEXT_REQ, null)
        {
            try
            {
                if ((object)dn == null)
                {
                    throw new ArgumentException(ExceptionMessages.PARAM_ERROR);
                }

                var encodedData = new MemoryStream();
                var encoder     = new LBEREncoder();

                var asn1_flags = new Asn1Integer(flags);
                var asn1_dn    = new Asn1OctetString(dn);

                asn1_flags.encode(encoder, encodedData);
                asn1_dn.encode(encoder, encodedData);

                setValue(SupportClass.ToSByteArray(encodedData.ToArray()));
            }
            catch (IOException ioe)
            {
                throw new LdapException(ExceptionMessages.ENCODING_ERROR, LdapException.ENCODING_ERROR, null, ioe);
            }
        }
Ejemplo n.º 5
0
        public void AddUserToOrganization(string userName, string password, string parentDistinguishedName)
        {
            var dn   = $"CN={userName},{parentDistinguishedName}";
            var mail = $"{userName}@{_ldapOptions.DomainName}";

            sbyte[] encodedBytes = SupportClass.ToSByteArray(Encoding.Unicode.GetBytes($"\"{password}\""));

            var attributeSet = new LdapAttributeSet
            {
                new LdapAttribute("instanceType", "4"),
                new LdapAttribute("objectCategory", $"CN=Person,CN=Schema,CN=Configuration,{_ldapOptions.DomainDistinguishedName}"),
                new LdapAttribute("objectClass", new[] { "top", "person", "organizationalPerson", "user" }),
                new LdapAttribute("name", userName),
                new LdapAttribute("cn", userName),
                new LdapAttribute("sAMAccountName", userName),
                new LdapAttribute("userPrincipalName", userName),
                new LdapAttribute("sn", userName),
                new LdapAttribute("displayName", userName),
                new LdapAttribute("unicodePwd", encodedBytes),
                new LdapAttribute("userAccountControl", "512"),
                new LdapAttribute("mail", mail),
            };
            var newEntry = new LdapEntry(dn, attributeSet);

            using (var ldapConnection = GetConnection())
            {
                ldapConnection.Add(newEntry);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Constructs an extended operations object for reading replica information.
        ///
        /// </summary>
        /// <param name="serverDN">The server on which the replica resides.
        ///
        /// </param>
        /// <param name="partitionDN">The distinguished name of the replica to be read.
        ///
        /// </param>
        /// <exception> LdapException A general exception which includes an error
        /// message and an Ldap error code.
        /// </exception>
        public GetReplicaInfoRequest(System.String serverDN, System.String partitionDN) : base(ReplicationConstants.GET_REPLICA_INFO_REQ, null)
        {
            try
            {
                if (((System.Object)serverDN == null) || ((System.Object)partitionDN == null))
                {
                    throw new System.ArgumentException(ExceptionMessages.PARAM_ERROR);
                }

                System.IO.MemoryStream encodedData = new System.IO.MemoryStream();
                LBEREncoder            encoder     = new LBEREncoder();

                Asn1OctetString asn1_serverDN    = new Asn1OctetString(serverDN);
                Asn1OctetString asn1_partitionDN = new Asn1OctetString(partitionDN);

                asn1_serverDN.encode(encoder, encodedData);
                asn1_partitionDN.encode(encoder, encodedData);

                setValue(SupportClass.ToSByteArray(encodedData.ToArray()));
            }
            catch (System.IO.IOException ioe)
            {
                throw new LdapException(ExceptionMessages.ENCODING_ERROR, LdapException.ENCODING_ERROR, (System.String)null);
            }
        }
        /// <summary> Constructs an extended operation object for checking effective rights.
        ///
        /// </summary>
        /// <param name="dn">       The distinguished name of the entry whose attribute is
        /// being checked.
        ///
        /// </param>
        /// <param name="trusteeDN">The distinguished name of the entry whose trustee rights
        /// are being returned
        ///
        /// </param>
        /// <param name="attrName"> The Ldap attribute name.
        ///
        /// </param>
        /// <exception> LdapException A general exception which includes an error
        /// message and an Ldap error code.
        /// </exception>

        public GetEffectivePrivilegesRequest(String dn, String trusteeDN, String attrName) : base(ReplicationConstants.GET_EFFECTIVE_PRIVILEGES_REQ, null)
        {
            try
            {
                if (((object)dn == null))
                {
                    throw new ArgumentException(ExceptionMessages.PARAM_ERROR);
                }

                System.IO.MemoryStream encodedData = new System.IO.MemoryStream();
                LBEREncoder            encoder     = new LBEREncoder();

                Asn1OctetString asn1_dn        = new Asn1OctetString(dn);
                Asn1OctetString asn1_trusteeDN = new Asn1OctetString(trusteeDN);
                Asn1OctetString asn1_attrName  = new Asn1OctetString(attrName);

                asn1_dn.encode(encoder, encodedData);
                asn1_trusteeDN.encode(encoder, encodedData);
                asn1_attrName.encode(encoder, encodedData);

                setValue(SupportClass.ToSByteArray(encodedData.ToArray()));
            }
            catch (System.IO.IOException ioe)
            {
                throw new LdapException(ExceptionMessages.ENCODING_ERROR, LdapException.ENCODING_ERROR, (String)null);
            }
        }
Ejemplo n.º 8
0
        void OnAddBinaryValueActivate(object o, EventArgs args)
        {
            FileChooserDialog fcd = new FileChooserDialog(
                Mono.Unix.Catalog.GetString("Select file to add as binary attribute"),
                Gtk.Stock.Open,
                null,
                FileChooserAction.Open);

            fcd.AddButton(Gtk.Stock.Cancel, ResponseType.Cancel);
            fcd.AddButton(Gtk.Stock.Open, ResponseType.Ok);

            fcd.SelectMultiple = false;

            ResponseType response = (ResponseType)fcd.Run();

            if (response == ResponseType.Ok)
            {
                byte[] fileBytes = ReadFileBytes(fcd.Filename);
                if (fileBytes.Length == 0)
                {
                    return;
                }

                string attributeName  = GetAttributeName();
                string attributeValue = Base64.encode(SupportClass.ToSByteArray(fileBytes));

                LdapEntry     le = conn.Data.GetEntry(currentDN);
                LdapAttribute la = le.getAttribute(attributeName);

                bool existing = false;
                if (la != null)
                {
                    existing = true;
                }

                LdapAttribute newla = new LdapAttribute(attributeName);
                newla.addBase64Value(attributeValue);

                LdapModification lm;

                if (existing)
                {
                    lm = new LdapModification(LdapModification.REPLACE, newla);
                }
                else
                {
                    lm = new LdapModification(LdapModification.ADD, newla);
                }

                List <LdapModification> modList = new List <LdapModification> ();
                modList.Add(lm);

                Util.ModifyEntry(conn, currentDN, modList.ToArray());

                this.Show(conn, conn.Data.GetEntry(currentDN), displayAll);
            }

            fcd.Destroy();
        }
Ejemplo n.º 9
0
        static void DoSearch(string ldapHost, int ldapPort, string loginDN, string password, string searchBase, string searchFilter)
        {
            try
            {
                LdapConnection conn = new LdapConnection();
                Console.WriteLine("Connecting to:" + ldapHost);
                conn.Connect(ldapHost, ldapPort);
                conn.Bind(loginDN, password);
                LdapSearchResults lsc = conn.Search(searchBase,
                                                    LdapConnection.SCOPE_SUB,
                                                    searchFilter,
                                                    null,
                                                    false);

                while (lsc.hasMore())
                {
                    LdapEntry nextEntry = null;
                    try
                    {
                        nextEntry = lsc.next();
                    }
                    catch (LdapException e)
                    {
                        Console.WriteLine("Error: " + e.LdapErrorMessage);
                        // Exception is thrown, go for next entry
                        continue;
                    }
                    Console.WriteLine("\n" + nextEntry.DN);
                    LdapAttributeSet attributeSet        = nextEntry.getAttributeSet();
                    System.Collections.IEnumerator ienum = attributeSet.GetEnumerator();
                    while (ienum.MoveNext())
                    {
                        LdapAttribute attribute     = (LdapAttribute)ienum.Current;
                        string        attributeName = attribute.Name;
                        string        attributeVal  = attribute.StringValue;
                        if (!Base64.isLDIFSafe(attributeVal))
                        {
                            byte[] tbyte = SupportClass.ToByteArray(attributeVal);
                            attributeVal = Base64.encode(SupportClass.ToSByteArray(tbyte));
                        }
                        Console.WriteLine(attributeName + "value:" + attributeVal);
                    }
                }
                conn.Disconnect();
            }
            catch (LdapException e)
            {
                Console.WriteLine("Error:" + e.LdapErrorMessage);
                return;
            }
            catch (Exception e)
            {
                Console.WriteLine("Error:" + e.Message);
                return;
            }
        }
Ejemplo n.º 10
0
        internal virtual void  writeImage(System.Drawing.Bitmap image)
        {
            //UPGRADE_TODO: Class 'java.awt.image.WritableRaster' was converted to 'System.Drawing.Bitmap' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_javaawtimageWritableRaster_3"'
            System.Drawing.Bitmap  raster = image;
            System.IO.MemoryStream tempDataBuffer;
            tempDataBuffer = new System.IO.MemoryStream();
            //UPGRADE_TODO: Method 'java.awt.image.Raster.getDataBuffer' was converted to 'System.Drawing.Bitmap' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_javaawtimageRastergetDataBuffer_3"'
            raster.Save(tempDataBuffer, System.Drawing.Imaging.ImageFormat.Bmp);
            System.Collections.ArrayList buffer = new System.Collections.ArrayList(tempDataBuffer.ToArray());
            //UPGRADE_TODO: Class 'java.awt.image.SampleModel' was converted to 'System.Drawing.Bitmap' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_javaawtimageSampleModel_3"'
            System.Drawing.Bitmap sampleModel = raster;
            int sampleSize = getPixelSize(sampleModel);
            //UPGRADE_ISSUE: Method 'java.awt.image.Raster.getSampleModelTranslateX' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtimageRastergetSampleModelTranslateX_3"'
            //UPGRADE_ISSUE: Method 'java.awt.image.Raster.getSampleModelTranslateY' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtimageRastergetSampleModelTranslateY_3"'
            int offset = (-raster.getSampleModelTranslateX() - raster.getSampleModelTranslateY() * sampleModel.Width) * sampleSize;
            int pitch  = sampleModel.Width * sampleSize;

            //		System.out.println("sample size " + sampleSize + " offset " + offset + " pitch " + pitch);

            if ((int)image.PixelFormat == (int)System.Drawing.Imaging.PixelFormat.Format24bppRgb)
            {
                //UPGRADE_ISSUE: Method 'java.awt.image.BufferedImage.getColorModel' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtimageBufferedImagegetColorModel_3"'
                SupportClass.IndexedColorArray cm = (SupportClass.IndexedColorArray)image.getColorModel();
                int     w      = image.Width;
                int     h      = image.Height;
                int[]   colors = new int[256];
                int[]   data   = new int[w * h];
                sbyte[] src    = SupportClass.ToSByteArray((byte[])((System.Collections.ArrayList)buffer)[0]);

                //UPGRADE_ISSUE: Method 'java.awt.image.IndexColorModel.getRGBs' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtimageIndexColorModelgetRGBs_int[]_3"'
                cm.getRGBs(colors);
                for (int i = 0; i < w * h; i++)
                {
                    data[i] = colors[(int)src[i] & 0xff];
                }
                write(0, 0, width, height, data, Format.A8R8G8B8);
                return;
            }


            if (buffer is System.Collections.ArrayList)
            {
                System.Collections.ArrayList byteBuffer = (System.Collections.ArrayList)buffer;
                write(0, 0, width, height, SupportClass.ToSByteArray((byte[])byteBuffer[0]), format, offset, pitch);
            }
            else if (buffer is System.Collections.ArrayList)
            {
                System.Collections.ArrayList intBuffer = (System.Collections.ArrayList)buffer;

                write(0, 0, width, height, (int[])intBuffer[0], format, offset / 4, pitch / 4);
            }
            else
            {
                throw new System.ArgumentException("Unsupported DataBuffer type");
            }
        }
Ejemplo n.º 11
0
        // Maps all sent LDAP Properties of the user into a Dictionary
        public static Dictionary <string, string> GetLdapUser(string ldapUid)
        {
            try
            {
                LdapConnection conn = new LdapConnection();
                conn.Connect(LdapHost, LdapPort);
                var lsc = conn.Search("ou=People,dc=fh-augsburg,dc=de",
                                      LdapConnection.SCOPE_ONE,
                                      $"uid={ldapUid}",
                                      null,
                                      false);

                var newDict = new Dictionary <string, string>();
                while (lsc.hasMore())
                {
                    LdapEntry nextEntry = null;
                    try
                    {
                        nextEntry = lsc.next();
                    }
                    catch (LdapException e)
                    {
                        Console.WriteLine("Error: " + e.LdapErrorMessage);
                        // Exception is thrown, go for next entry
                        continue;
                    }
                    LdapAttributeSet attributeSet        = nextEntry.getAttributeSet();
                    System.Collections.IEnumerator ienum = attributeSet.GetEnumerator();
                    while (ienum.MoveNext())
                    {
                        LdapAttribute attribute     = (LdapAttribute)ienum.Current;
                        string        attributeName = attribute.Name;
                        string        attributeVal  = attribute.StringValue;
                        if (!Base64.isLDIFSafe(attributeVal))
                        {
                            byte[] tbyte = SupportClass.ToByteArray(attributeVal);
                            attributeVal = Base64.encode(SupportClass.ToSByteArray(tbyte));
                        }
                        newDict.Add(attributeName, attributeVal);
                    }
                }
                conn.Disconnect();
                return(newDict);
            }
            catch (LdapException e)
            {
                Console.WriteLine("Error:" + e.LdapErrorMessage);
                return(null);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error:" + e.Message);
                return(null);
            }
        }
Ejemplo n.º 12
0
        public static System.String getString(Document doc)
        {
            System.IO.MemoryStream bos = getStream(doc);

            sbyte[] byteArr   = SupportClass.ToSByteArray(bos.ToArray());
            char[]  charArray = new char[byteArr.Length];
            for (int i = 0; i < byteArr.Length; i++)
            {
                charArray[i] = (char)byteArr[i];
            }

            return(System.Convert.ToString(charArray));
        }
Ejemplo n.º 13
0
        /// <summary> Constructs an RfcLDAPSuperDN object from a String object.
        /// </summary>
        /// <param name="content"> A string value that will be contained in the this RfcLDAPSuperDN object </param>
        public RfcLdapSuperDN(String s) : base(ID, new Asn1OctetString(s), false)         //type is encoded IMPLICITLY
        {
            try {
                System.Text.Encoding encoder = System.Text.Encoding.GetEncoding("utf-8");
                byte[]  ibytes = encoder.GetBytes(s);
                sbyte[] sbytes = SupportClass.ToSByteArray(ibytes);

                this.content = sbytes;
            }
            catch (System.IO.IOException uee) {
                throw new System.SystemException(uee.ToString());
            }
        }
Ejemplo n.º 14
0
 /// <summary> Checks if the input String contains only safe values, that is,
 /// the data does not need to be encoded for use with LDIF.
 /// The rules for checking safety are based on the rules for LDIF
 /// (Ldap Data Interchange Format) per RFC 2849.  The data does
 /// not need to be encoded if all the following are true:
 ///
 /// The data cannot start with the following char values:
 /// <pre>
 /// 00 (NUL)
 /// 10 (LF)
 /// 13 (CR)
 /// 32 (SPACE)
 /// 58 (:)
 /// 60 (LESSTHAN)
 /// Any character with value greater than 127
 /// </pre>
 /// The data cannot contain any of the following char values:
 /// <pre>
 /// 00 (NUL)
 /// 10 (LF)
 /// 13 (CR)
 /// Any character with value greater than 127
 /// </pre>
 /// The data cannot end with a space.
 ///
 /// </summary>
 /// <param name="str">the String to be checked.
 ///
 /// </param>
 /// <returns> true if encoding not required for LDIF
 /// </returns>
 public static bool isLDIFSafe(System.String str)
 {
     try
     {
         System.Text.Encoding encoder = System.Text.Encoding.GetEncoding("utf-8");
         byte[]  ibytes = encoder.GetBytes(str);
         sbyte[] sbytes = SupportClass.ToSByteArray(ibytes);                               return(isLDIFSafe(sbytes));
     }
     catch (System.IO.IOException ue)
     {
         throw new System.SystemException("UTF-8 String encoding not supported by JVM");
     }
 }
Ejemplo n.º 15
0
 private void  sendMessage(System.String theMessage)
 {
     sbyte[] temp_sbyteArray;
     temp_sbyteArray = SupportClass.ToSByteArray(SupportClass.ToByteArray(HL7_START_OF_MESSAGE));
     os.Write(SupportClass.ToByteArray(temp_sbyteArray), 0, temp_sbyteArray.Length);
     sbyte[] temp_sbyteArray2;
     temp_sbyteArray2 = SupportClass.ToSByteArray(SupportClass.ToByteArray(theMessage));
     os.Write(SupportClass.ToByteArray(temp_sbyteArray2), 0, temp_sbyteArray2.Length);
     sbyte[] temp_sbyteArray3;
     temp_sbyteArray3 = SupportClass.ToSByteArray(SupportClass.ToByteArray(HL7_END_OF_MESSGAE));
     os.Write(SupportClass.ToByteArray(temp_sbyteArray3), 0, temp_sbyteArray3.Length);
     os.WriteByte((System.Byte) 13);
     os.Flush();
 }
Ejemplo n.º 16
0
 /// <summary>
 ///     Checks if the input String contains only safe values, that is,
 ///     the data does not need to be encoded for use with LDIF.
 ///     The rules for checking safety are based on the rules for LDIF
 ///     (Ldap Data Interchange Format) per RFC 2849.  The data does
 ///     not need to be encoded if all the following are true:
 ///     The data cannot start with the following char values:
 ///     <pre>
 ///         00 (NUL)
 ///         10 (LF)
 ///         13 (CR)
 ///         32 (SPACE)
 ///         58 (:)
 ///         60 (LESSTHAN)
 ///         Any character with value greater than 127
 ///     </pre>
 ///     The data cannot contain any of the following char values:
 ///     <pre>
 ///         00 (NUL)
 ///         10 (LF)
 ///         13 (CR)
 ///         Any character with value greater than 127
 ///     </pre>
 ///     The data cannot end with a space.
 /// </summary>
 /// <param name="str">
 ///     the String to be checked.
 /// </param>
 /// <returns>
 ///     true if encoding not required for LDIF
 /// </returns>
 public static bool isLDIFSafe(string str)
 {
     try
     {
         var encoder = Encoding.GetEncoding("utf-8");
         var ibytes  = encoder.GetBytes(str);
         var sbytes  = SupportClass.ToSByteArray(ibytes);
         return(isLDIFSafe(sbytes));
     }
     catch (IOException ue)
     {
         throw new Exception("UTF-8 String encoding not supported by JVM", ue);
     }
 }
Ejemplo n.º 17
0
 public static sbyte[] serialize(System.Object o)
 {
     System.IO.MemoryStream baos = new System.IO.MemoryStream();
     try
     {
         //UPGRADE_TODO: Class 'java.io.DataOutputStream' was converted to 'System.IO.BinaryWriter' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataOutputStream'"
         write(new System.IO.BinaryWriter(baos), o);
     }
     catch (System.IO.IOException ioe)
     {
         throw new System.SystemException("IOException writing to ByteArrayOutputStream; shouldn't happen!");
     }
     return(SupportClass.ToSByteArray(baos.ToArray()));
 }
Ejemplo n.º 18
0
 /// <summary>
 ///     Encodes the specified String into a base64 encoded String object.
 /// </summary>
 /// <param name="inputString">
 ///     The String object to be encoded.
 /// </param>
 /// <returns>
 ///     a String containing the encoded value of the input.
 /// </returns>
 public static string encode(string inputString)
 {
     try
     {
         var encoder = Encoding.GetEncoding("utf-8");
         var ibytes  = encoder.GetBytes(inputString);
         var sbytes  = SupportClass.ToSByteArray(ibytes);
         return(encode(sbytes));
     }
     catch (IOException ue)
     {
         throw new Exception("US-ASCII String encoding not supported by JVM", ue);
     }
 }
Ejemplo n.º 19
0
 /// <summary> Encodes the specified String into a base64 encoded String object.
 ///
 /// </summary>
 /// <param name="inputString"> The String object to be encoded.
 ///
 /// </param>
 /// <returns> a String containing the encoded value of the input.
 /// </returns>
 public static System.String encode(System.String inputString)
 {
     try
     {
         System.Text.Encoding encoder = System.Text.Encoding.GetEncoding("utf-8");
         byte[]  ibytes = encoder.GetBytes(inputString);
         sbyte[] sbytes = SupportClass.ToSByteArray(ibytes);
         return(encode(sbytes));
     }
     catch (System.IO.IOException ue)
     {
         throw new System.SystemException("US-ASCII String encoding not supported by JVM");
     }
 }
Ejemplo n.º 20
0
 /// <summary> Encodes the specified String into a base64 encoded String object.
 ///
 /// </summary>
 /// <param name="inputString"> The String object to be encoded.
 ///
 /// </param>
 /// <returns> a String containing the encoded value of the input.
 /// </returns>
 public static string encode(string inputString)
 {
     try
     {
         Encoding encoder = Encoding.GetEncoding("utf-8");
         byte[]   ibytes  = encoder.GetBytes(inputString);
         sbyte[]  sbytes  = SupportClass.ToSByteArray(ibytes);
         return(encode(sbytes));
     }
     catch (IOException)
     {
         throw new SystemException("UTF-8 String encoding not supported");
     }
 }
Ejemplo n.º 21
0
 public sbyte[] getEncoding(Asn1Encoder enc)
 {
     System.IO.MemoryStream out_Renamed = new System.IO.MemoryStream();
     try
     {
         encode(enc, out_Renamed);
     }
     catch (System.IO.IOException e)
     {
         // Should never happen - the current Asn1Object does not have
         // a encode method.
         throw new System.Exception("IOException while encoding to byte array: " + e.ToString());
     }
     return(SupportClass.ToSByteArray(out_Renamed.ToArray()));
 }
Ejemplo n.º 22
0
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="name"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static bool UpdatePassword(string loginName, string password)
        {
            LdapEntry entry = GetUser(loginName);

            if (entry == null)
            {
                throw new Exception($"名为:{loginName} 的用户在AD中不存在");
            }

            password = $"\"{password}\"";
            sbyte[]       encodedBytes      = SupportClass.ToSByteArray(Encoding.Unicode.GetBytes(password));
            LdapAttribute attributePassword = new LdapAttribute("unicodePwd", encodedBytes);

            _connection.Modify(entry.DN, new LdapModification(LdapModification.REPLACE, attributePassword));

            return(true);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Read bytes from an input stream into a byte array then close the input
        /// stream
        ///
        /// </summary>
        /// <param name="in">
        /// </param>
        /// <param name="len">
        /// </param>
        /// <returns>
        /// </returns>
        /// <throws>  IOException </throws>
        public static sbyte[] readFromStream(System.IO.Stream in_Renamed, int len)
        {
            sbyte[] data;
            int     read;

            if (len >= 0)
            {
                data = new sbyte[len];
                read = 0;
                while (read < len)
                {
                    int k = in_Renamed is org.javarosa.core.io.BufferedInputStream?((org.javarosa.core.io.BufferedInputStream)in_Renamed).read(data, read, len - read):SupportClass.ReadInput(in_Renamed, data, read, len - read);
                    if (k == -1)
                    {
                        break;
                    }
                    read += k;
                }
            }
            else
            {
                System.IO.MemoryStream buffer = new System.IO.MemoryStream();
                while (true)
                {
                    int b = in_Renamed.ReadByte();
                    if (b == -1)
                    {
                        break;
                    }
                    buffer.WriteByte((System.Byte)b);
                }
                data = SupportClass.ToSByteArray(buffer.ToArray());
                read = data.Length;
            }

            if (len > 0 && read < len)
            {
                // System.out.println("WARNING: expected " + len + "!!");
                throw new System.SystemException("expected: " + len + " bytes but read " + read);
            }
            // replyS
            // System.out.println(new String(data, "UTF-8"));

            return(data);
        }
Ejemplo n.º 24
0
 internal static void append8BitBytes(System.String content, BitVector bits, System.String encoding)
 {
     sbyte[] bytes;
     try
     {
         //UPGRADE_TODO: Method 'java.lang.String.getBytes' was converted to 'System.Text.Encoding.GetEncoding(string).GetBytes(string)' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javalangStringgetBytes_javalangString'"
         bytes = SupportClass.ToSByteArray(System.Text.Encoding.GetEncoding(encoding).GetBytes(content));
     }
     catch (System.IO.IOException uee)
     {
         //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
         throw new WriterException(uee.ToString());
     }
     for (int i = 0; i < bytes.Length; ++i)
     {
         bits.appendBits(bytes[i], 8);
     }
 }
Ejemplo n.º 25
0
        /// <summary> Constructs an attribute with a single string value.
        ///
        /// </summary>
        /// <param name="attrName">Name of the attribute.
        /// </param>
        /// <param name="attrString">Value of the attribute as a string.
        ///
        /// @throws IllegalArgumentException if attrName or attrString is null
        /// </param>
        public LdapAttribute(string attrName, string attrString) : this(attrName)
        {
            if ((object)attrString == null)
            {
                throw new ArgumentException("Attribute value cannot be null");
            }
            try
            {
                System.Text.Encoding encoder = System.Text.Encoding.GetEncoding("utf-8");
                byte[]  ibytes = encoder.GetBytes(attrString);
                sbyte[] sbytes = SupportClass.ToSByteArray(ibytes);

                add(sbytes);
            }
            catch (System.IO.IOException e)
            {
                throw new Exception(e.ToString());
            }
        }
Ejemplo n.º 26
0
        /// <summary>  Description of the Method
        ///
        /// </summary>
        /// <param name="value"> Description of the Parameter
        /// </param>
        private void  fillWriteBuffer(System.String value_Renamed)
        {
            int len = value_Renamed.Length;

            sbyte[] buffer = SupportClass.ToSByteArray(SupportClass.ToByteArray(value_Renamed));

            if (len < (recordSize - 1))
            {
                //account for end of line char
                Array.Copy(SupportClass.ToByteArray(buffer), 0, SupportClass.ToByteArray(writeBuffer), 0, len);
                Array.Copy(SupportClass.ToByteArray(zapBuffer), 0, SupportClass.ToByteArray(writeBuffer), len, recordSize - len - 1);
                writeBuffer[recordSize - 1] = Convert.ToSByte('\n');
            }
            else
            {
                Array.Copy(SupportClass.ToByteArray(buffer), 0, SupportClass.ToByteArray(writeBuffer), 0, recordSize - 1);
                writeBuffer[recordSize - 1] = zapBuffer[recordSize - 1];
            }
        }
Ejemplo n.º 27
0
 /// <summary> Adds a string value to the attribute.
 ///
 /// </summary>
 /// <param name="attrString">Value of the attribute as a String.
 ///
 /// @throws IllegalArgumentException if attrString is null
 /// </param>
 public virtual void addValue(string attrString)
 {
     if ((object)attrString == null)
     {
         throw new ArgumentException("Attribute value cannot be null");
     }
     try
     {
         System.Text.Encoding encoder = System.Text.Encoding.GetEncoding("utf-8");
         byte[]  ibytes = encoder.GetBytes(attrString);
         sbyte[] sbytes = SupportClass.ToSByteArray(ibytes);
         add(sbytes);
         //				this.add(attrString.getBytes("UTF-8"));
     }
     catch (System.IO.IOException ue)
     {
         throw new Exception(ue.ToString());
     }
 }
Ejemplo n.º 28
0
        public static sbyte[] getClassHash(System.Type type)
        {
            sbyte[] hash = new sbyte[CLASS_HASH_SIZE];
            //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Class.getName' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
            sbyte[] md5 = MD5.hash(SupportClass.ToSByteArray(SupportClass.ToByteArray(type.FullName)));             //add support for a salt, in case of collision?

            for (int i = 0; i < hash.Length; i++)
            {
                hash[i] = md5[i];
            }
            sbyte[] badHash = new sbyte[] { 0, 4, 78, 97 };
            if (PrototypeFactory.compareHash(badHash, hash))
            {
                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Class.getName' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                System.Console.Out.WriteLine("BAD CLASS: " + type.FullName);
            }

            return(hash);
        }
Ejemplo n.º 29
0
 public virtual IDataPayload createSerializedPayload(FormInstance model, IDataReference ref_Renamed)
 {
     init();
     rootRef = org.javarosa.core.model.instance.FormInstance.unpackReference(ref_Renamed);
     if (this.serializer == null)
     {
         this.AnswerDataSerializer = new XFormAnswerDataSerializer();
     }
     model.accept(this);
     if (theSmsStr != null)
     {
         //UPGRADE_TODO: Method 'java.lang.String.getBytes' was converted to 'System.Text.Encoding.GetEncoding(string).GetBytes(string)' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javalangStringgetBytes_javalangString'"
         sbyte[] form = SupportClass.ToSByteArray(System.Text.Encoding.GetEncoding("UTF-16").GetBytes(theSmsStr));
         return(new ByteArrayPayload(form, null, org.javarosa.core.services.transport.payload.IDataPayload_Fields.PAYLOAD_TYPE_SMS));
     }
     else
     {
         return(null);
     }
 }
Ejemplo n.º 30
0
 /*
  * (non-Javadoc)
  * @see org.javarosa.core.model.utils.IInstanceSerializingVisitor#serializeInstance(org.javarosa.core.model.instance.FormInstance, org.javarosa.core.model.IDataReference)
  */
 public virtual sbyte[] serializeInstance(FormInstance model, IDataReference ref_Renamed)
 {
     init();
     rootRef = org.javarosa.core.model.instance.FormInstance.unpackReference(ref_Renamed);
     if (this.serializer == null)
     {
         this.AnswerDataSerializer = new XFormAnswerDataSerializer();
     }
     model.accept(this);
     if (theSmsStr != null)
     {
         //Encode in UTF-16 by default, since it's the default for complex messages
         //UPGRADE_TODO: Method 'java.lang.String.getBytes' was converted to 'System.Text.Encoding.GetEncoding(string).GetBytes(string)' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javalangStringgetBytes_javalangString'"
         return(SupportClass.ToSByteArray(System.Text.Encoding.GetEncoding("UTF-16BE").GetBytes(theSmsStr)));
     }
     else
     {
         return(null);
     }
 }