⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shaibuttoncoprvm.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    *         adapter    *    * @see #SHAiButtonCoprVM(String)    * @see #SHAiButtonCoprVM(String,byte[],byte[])    * @see #SHAiButtonCoprVM(OneWireContainer,String)    * @see #SHAiButtonCoprVM(OneWireContainer18,String,byte[],byte[])    * @see #SHAiButtonCoprVM(byte[],int,int,int,int,int,byte,byte[],byte[],byte[],byte[],byte[],byte[],byte[],byte[],byte[])    */   public SHAiButtonCoprVM(OneWireContainer owc, String filename,                           byte[] sign_secret, byte[] auth_secret)      throws OneWireException, OneWireIOException   {      if(!load(owc,filename))         throw new OneWireIOException("failed to load config info");      if(!installMasterSecret(signPageNumber, sign_secret, signPageNumber&7))         throw new OneWireIOException("failed to install system signing secret");      if(!installMasterSecret(authPageNumber, auth_secret, authPageNumber&7))         throw new OneWireIOException("failed to install authentication secret");   }   /**    * <p>Simulates a specific DS1963S coprocessor device.  First, the given    * TMEX file name is loaded of the container to get all the parameters of    * the coprocessor.  Then (since secrets are not readable off the iButton,    * they must be provided) the secrets are installed on the virtual    * coprocessor.</p>    *    * @param owc The coprocessor button this VM will simulate.    * @param filename The TMEX filename of the coprocessor service file ("COPR.0")    * @param sign_secret The system data signing secret.    * @param auth_secret The system device authentication secret.    *    * @throws 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'.    * @throws OneWireException on a communication or setup error with the 1-Wire    *         adapter    *    * @see #SHAiButtonCoprVM(String)    * @see #SHAiButtonCoprVM(String,byte[],byte[])    * @see #SHAiButtonCoprVM(OneWireContainer,String)    * @see #SHAiButtonCoprVM(OneWireContainer,String,byte[],byte[])    * @see #SHAiButtonCoprVM(byte[],int,int,int,int,int,byte,byte[],byte[],byte[],byte[],byte[],byte[],byte[],byte[],byte[])    */   public SHAiButtonCoprVM(OneWireContainer18 owc, String filename,                           byte[] sign_secret, byte[] auth_secret)      throws OneWireException, OneWireIOException   {      if(!load(owc,filename))         throw new OneWireIOException("failed to load config info");      if(!installMasterSecret(signPageNumber, sign_secret, signPageNumber&7))         throw new OneWireIOException("failed to install system signing secret");      if(!installMasterSecret(authPageNumber, auth_secret, authPageNumber&7))         throw new OneWireIOException("failed to install authentication secret");   }   // ***********************************************************************   // End Constructors   // ***********************************************************************   // ***********************************************************************   // Save and Load methods for serializing all data   // ***********************************************************************   /**    * <p>Saves simulated coprocessor configuration info to an (almost)    * standard-format to a hard drive file.</p>    *    * @param filename The filename of the simulated coprocessor's data    *        file ("shaCopr.dat")    * @param saveSecretData If <code>true</true>, the raw secret information    *        is also written to the file    *    * @throws 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'.    * @throws OneWireException on a communication or setup error with the 1-Wire    *         adapter    *    * @return <code>true</code> if the info was successfully saved    */   public boolean save(String filename, boolean saveSecretData)      throws OneWireException, OneWireIOException   {      try      {         //Create the configuration file         FileOutputStream fos = new FileOutputStream(filename);         //write the data out to the config file         toStream(fos);         //non-standard additions         fos.write(address,0,8);         for(int i=0; i<8; i++)         {            if(saveSecretData)               fos.write(secretPage[i]);            else               fos.write(NullSecret);         }         fos.flush();         fos.close();         return true;      }      catch(Exception e)      {         return false;      }   }   /**    * <p>Saves simulated coprocessor configuration info to an (almost)    * standard-format to a 1-Wire Memory Device's TMEX file.</p>    *    * @param owc 1-Wire Memory Device with valid TMEX file structure.    * @param filename The TMEX filename of the simulated coprocessor's data    *        file ("COPR.2")    * @param saveSecretData If <code>true</true>, the raw secret information    *        is also written to the file.    *    * @throws 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'.    * @throws OneWireException on a communication or setup error with the 1-Wire    *         adapter    *    * @return <code>true</code> if the info was successfully saved    */   public boolean save(OneWireContainer owc, String filename,                       boolean saveSecretData)      throws OneWireException, OneWireIOException   {      try      {         //Create the configuration file         OWFileOutputStream fos = new OWFileOutputStream(owc, filename);         //write the data out         toStream(fos);         //non-standard additions         fos.write(address,0,8);         for(int i=0; i<8; i++)         {            if(saveSecretData)               fos.write(secretPage[i]);            else               fos.write(NullSecret);         }         fos.flush();         fos.close();         return true;      }      catch(Exception ioe)      {         return false;      }   }   /**    * <p>Loads coprocessor configuration information from an (almost) standard    * service file on hard drive. If secret information was saved, this routine    * automatically loads it.</P>    *    * @param filename The filename of the simulated coprocessor's data    *        file ("shaCopr.dat")    *    * @return <code>true</code> if the info was successfully loaded    */   public boolean load(String filename)   {      try      {         //open the file containing config info         FileInputStream fis = new FileInputStream(filename);         //load info from the file stream         fromStream(fis);         //non-standard file components         if(fis.available()>0)         {            fis.read(this.address,0,8);            for(int i=0; i<8 && fis.available()>0; i++)            {               fis.read(secretPage[i]);            }         }         fis.close();         return true;      }      catch(Exception e)      {         return false;      }   }   /**    * <p>Loads coprocessor configuration information from an (almost) standard    * service TMEX file on 1-Wire memory device. If secret information was saved,    * this routine automatically loads it.</P>    *    * @param owc 1-Wire memory device with valid TMEX file structure    * @param filename The TMEX filename of the simulated coprocessor's data    *        file ("COPR.2")    *    * @return <code>true</code> if the info was successfully loaded    */   public boolean load(OneWireContainer owc, String filename)   {      try      {         //open the file containing config info         OWFileInputStream fis = new OWFileInputStream(owc,filename);         //load info from the file stream         fromStream(fis);         //non-standard file components         if(fis.available()>0)         {            fis.read(this.address,0,8);            for(int i=0; i<8 && fis.available()>0; i++)            {               fis.read(secretPage[i]);            }         }         fis.close();         return true;      }      catch(Exception e)      {         return false;      }   }   /**    * <p>Loads coprocessor configuration information from a standard TMEX    * service file on a DS1963S.</P>    *    * @param owc DS1963S set up as a valid coprocessor    * @param filename The TMEX filename of the coprocessor's data    *        file ("COPR.0")    *    * @return <code>true</code> if the info was successfully loaded    */   public boolean load(OneWireContainer18 owc, String filename)   {      try      {         //open the file containing config info         OWFileInputStream fis = new OWFileInputStream(owc,filename);         //load info from the file stream         fromStream(fis);         //non-standard components         System.arraycopy(owc.getAddress(),0,this.address,0,8);         fis.close();         return true;      }      catch(Exception e)      {         e.printStackTrace();         return false;      }   }   // ***********************************************************************   // End Save and Load methods   // ***********************************************************************   // ***********************************************************************   // Begin SHA iButton Methods   // ***********************************************************************   /**    * <P>Given a 32-byte array for page data and a 32-byte array for    * scratchpad content, this function will create a 20-byte signature    * for the data based on SHA-1.  The format of the calculation of the    * data signature is as follows: First 4-bytes of signing secret,    * 32-bytes of accountData, 12 bytes of scratchpad data starting at    * index 8, last 4-bytes of signing secret, 3 bytes of scratchpad data    * starting at index 20, and the rest is padding as specified for    * standard SHA-1.  This is all laid out, in detail, in the DS1963S    * data sheet.</P>    *    * <P>The resulting 20-byte signature is copied into    * <code>mac_buffer</code> starting at <code>macStart</code>.  If you're    * updating a signature that already exists in the accountData array,    * it is acceptable to call the method like so:    * <code><pre>    *   copr.createDataSignature(accountData, spad, accountData, 8);    * </pre></code>    * assuming that the signature starts at index 8 of the accountData    * array.</p>    *    * @param accountData the 32-byte data page for which the signature is    *        generated.    * @param signScratchpad the 32-byte scratchpad contents for which the    *        signature is generated.  This will contain parameters such    *        as the user's write cycle counter for the page, the user's    *        1-wire address, and the page number where account data is    *        stored.    * @param mac_buffer used to return the 20-byte signature generated    *        by signing the page using the coprocessor's system signing    *        secret.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -