示例#1
0
        /// <summary>
        /// <P>Creates a mostly unitialized SHAiButtonUser object.  This constructor
        /// merely copies the coprocessors 7 byte binding code into a local cache
        /// and stores the name of the account service file used for all user
        /// iButtons.</P>
        ///
        /// <P>Since this constructor leaves data unitialized, you should be very
        /// careful with the use of it.  It is expected that after calling this
        /// constructor, the user will call <code>setiButton</code> to finish the
        /// initialization process.  On memory-starved platforms, this should help
        /// optimize memory usage.</P>
        /// </summary>
        /// <param name="copr"> The SHAiButtonCopr to which the user object is tied.  This
        ///        Coprocessor contains the necessary binding code and service
        ///        filename, necessary for both locating a user and recreating his
        ///        unique secret.
        /// </param>
        /// <seealso cref= #SHAiButtonUser18(SHAiButtonCopr,OneWireContainer18,bool,byte[]) </seealso>
        /// <seealso cref= #SHAiButtonUser18(SHAiButtonCopr) </seealso>
        public SHAiButtonUser18(SHAiButtonCopr copr)
        {
            //save a copy of the binding code
            copr.getBindCode(this.fullBindCode, 0);
            Array.Copy(this.fullBindCode, 4, this.fullBindCode, 12, 3);

            //create string representation of service filename
            copr.getFilename(this.serviceFile, 0);
            this.strServiceFilename = Encoding.Unicode.GetString(this.serviceFile) + "." + (int)copr.FilenameExt;
        }
        /// <summary>
        /// <P>Creates a mostly unitialized SHAiButtonUser object.  This constructor
        /// merely copies the coprocessors 7 byte binding code into a local cache
        /// and stores the name of the account service file used for all user
        /// iButtons.</P>
        ///
        /// <P>Since this constructor leaves data unitialized, you should be very
        /// careful with the use of it.  It is expected that after calling this
        /// constructor, the user will call <code>setiButton</code> to finish the
        /// initialization process.  On memory-starved platforms, this should help
        /// optimize memory usage.</P>
        ///
        /// <P>Note: The same coprocessor can be used for write-authorization as
        /// authentication if you're transaction system is using unsigned transaction
        /// data.</P>
        /// </summary>
        /// <param name="copr"> The SHAiButtonCopr to which the user object is tied.  This
        ///        Coprocessor contains the necessary binding code and service
        ///        filename, necessary for both locating a user and recreating his
        ///        unique secret. </param>
        /// <param name="authCopr"> The SHAiButtonCopr used to generate the write-authorization
        ///        MAC for the copy-scratchpad command of the DS1961S.
        ///
        /// </param>
        /// <seealso cref= #SHAiButtonUser33(SHAiButtonCopr,OneWireContainer33,bool,byte[]) </seealso>
        /// <seealso cref= #SHAiButtonUser33(SHAiButtonCopr,SHAiButtonCopr,OneWireContainer33) </seealso>
        public SHAiButtonUser33(SHAiButtonCopr copr, SHAiButtonCopr authCopr)
        {
            //hold a reference to the coprocessor
            this.copr = authCopr;

            //make sure fullBindCode has appropriate ff padding
            Array.Copy(ffBlock, 0, this.fullBindCode, 0, 15);

            //create string representation of service filename
            copr.getFilename(this.serviceFile, 0);
            this.strServiceFilename = Encoding.Unicode.GetString(this.serviceFile) + "." + (int)copr.FilenameExt;
        }
        /// <summary>
        /// <P>Creates a valid SHAiButtonUser object.  If the service file,
        /// whose name is taken from the <code>SHAiButtonCopr</code>, is not
        /// found on the user iButton, a OneWireException is thrown with the
        /// message "Invalid SHA user".</P>
        ///
        /// <P>Note: The same coprocessor can be used for write-authorization as
        /// authentication if you're transaction system is using unsigned transaction
        /// data.</P>
        /// </summary>
        /// <param name="coprBindCode"> The Coprocessor Bind Code without the information. </param>
        /// <param name="fileName"> The file name from the Coprocessor. </param>
        /// <param name="fileNameExt"> The file extenstion from the Coprocessor </param>
        /// <param name="authCopr"> The SHAiButtonCopr used to generate the write-authorization
        ///        MAC for the copy-scratchpad command of the DS1961S. </param>
        /// <param name="owc"> The DS1961S iButton that this object will refer to.
        /// </param>
        /// <exception cref="OneWireIOException"> on a 1-Wire communication error such as
        ///         reading an incorrect CRC from a 1-Wire device.  This could be
        ///         caused by a physical interruption in the 1-Wire Network due to
        ///         shorts or a newly arriving 1-Wire device issuing a 'presence pulse'. </exception>
        /// <exception cref="OneWireException"> on a communication or setup error with the 1-Wire
        ///         adapter
        /// </exception>
        /// <seealso cref= #SHAiButtonUser33(SHAiButtonCopr,OneWireContainer33,bool,byte[]) </seealso>
        /// <seealso cref= #SHAiButtonUser33(SHAiButtonCopr,SHAiButtonCopr) </seealso>
        public SHAiButtonUser33(byte[] coprBindCode, byte[] fileName, int fileNameExt, OneWireContainer33 owc)
        {
            //make sure fullBindCode has appropriate ff padding
            Array.Copy(ffBlock, 0, this.fullBindCode, 0, 15);

            //create string representation of service filename
            copr.getFilename(this.serviceFile, 0);
            this.strServiceFilename = Encoding.Unicode.GetString(fileName) + "." + (int)fileNameExt;

            //hold container reference and address
            if (!setiButton33(owc))
            {
                throw new OneWireException("Invalid SHA user");
            }
        }