Package org.nfctools.ndef.wkt.records

Examples of org.nfctools.ndef.wkt.records.SignatureRecord


public class SignatureRecordDecoder implements WellKnownRecordPayloadDecoder {

  @Override
  public WellKnownRecord decodePayload(byte[] payload, NdefMessageDecoder messageDecoder) {
    SignatureRecord signatureRecord = new SignatureRecord();
   
    try {
      ByteArrayInputStream bais = new ByteArrayInputStream(payload);

      int version = bais.read();
     
      signatureRecord.setVersion((byte)version);
     
      int header = bais.read();
      boolean signatureUriPresent = (header & 0x80) != 0;
      SignatureType type = SignatureType.toSignatureType((header & 0x7F));
     
      signatureRecord.setSignatureType(type);
     
      if(signatureUriPresent || type != SignatureType.NOT_PRESENT) {
       
        int size = RecordUtils.readUnsignedShort(bais);

        if(size > 0) {
          byte[] signatureOrUri = RecordUtils.readByteArray(bais, size);
 
          if(signatureUriPresent) {
            signatureRecord.setSignatureUri(new String(signatureOrUri, NdefConstants.UTF_8_CHARSET));
          } else {
            signatureRecord.setSignature(signatureOrUri);
          }
        }
       
        int certificateHeader = bais.read();
       
        signatureRecord.setCertificateFormat(CertificateFormat.toCertificateFormat((certificateHeader >> 4) & 0x7));
       
        int numberOfCertificates = certificateHeader & 0xF;

        for(int i = 0; i < numberOfCertificates; i++) {
          int certificateSize = RecordUtils.readUnsignedShort(bais);

          byte[] certificate = RecordUtils.readByteArray(bais, certificateSize);
         
          signatureRecord.add(certificate);
        }
       
        if((certificateHeader & 0x80) != 0) { // has certificate uri
          int certificateUriSize = RecordUtils.readUnsignedShort(bais);

          byte[] certificateUri = RecordUtils.readByteArray(bais, certificateUriSize);
         
          signatureRecord.setCertificateUri(new String(certificateUri, NdefConstants.UTF_8_CHARSET));
        }
       
      } else {
        // start marker
      }
View Full Code Here


public class SignatureRecordEncoder implements WellKnownRecordPayloadEncoder {

  @Override
  public byte[] encodePayload(WellKnownRecord wellKnownRecord, NdefMessageEncoder messageEncoder) {
    SignatureRecord myRecord = (SignatureRecord )wellKnownRecord;
    return createPayload(messageEncoder, myRecord);
  }
View Full Code Here

TOP

Related Classes of org.nfctools.ndef.wkt.records.SignatureRecord

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.