コード例 #1
0
  @Override
  public ISecurityHandler getSecurityHandler(COSEncryption encryption) throws COSSecurityException {
    COSName name = encryption.getFilter();
    if (name == null) {
      throw new COSSecurityException("security handler not specified"); // $NON-NLS-1$
    }
    if (name.equals(CN_Standard)) {
      int revision = encryption.getFieldInt(DK_R, 0);
      if (revision == 2) {
        return new StandardSecurityHandlerR2();
      } else if (revision == 3) {
        return new StandardSecurityHandlerR3();
      } else if (revision == 4) {
        return new StandardSecurityHandlerR4();
      } else {
        return new StandardSecurityHandlerR2();
      }
    }

    // maybe provide a registry some day
    throw new COSSecurityException(
        "no security handler '" //$NON-NLS-1$
            + name.stringValue()
            + "'"); //$NON-NLS-1$
  }
コード例 #2
0
 @Override
 public void detach(STDocument doc) throws COSSecurityException {
   if (doc == null) {
     return;
   }
   COSEncryption encryption = getEncryption();
   encryption.cosRemoveField(COSEncryption.DK_Filter);
   encryption.cosRemoveField(StandardSecurityHandler.DK_R);
   encryption.cosRemoveField(StandardSecurityHandler.DK_P);
   super.detach(doc);
 }
コード例 #3
0
 @Override
 public void attach(STDocument doc) {
   super.attach(doc);
   if (doc == null) {
     return;
   }
   COSEncryption encryption = getEncryption();
   encryption.cosSetField(COSEncryption.DK_Filter, StandardSecurityHandlerFactory.CN_Standard);
   encryption.cosSetField(StandardSecurityHandler.DK_R, COSInteger.create(getRevision()));
   // apply default permissions
   getEncryption().setFieldInt(StandardSecurityHandler.DK_P, DEFAULT_ACCESS_PERMISSIONS);
 }
コード例 #4
0
 @Override
 protected void initializeFromScratch() {
   super.initializeFromScratch();
   COSEncryption encryption = getEncryption();
   encryption.setFieldInt(COSEncryption.DK_Length, DEFAULT_LENGTH);
 }
コード例 #5
0
 public void setLength(int length) {
   COSEncryption encryption = getEncryption();
   encryption.setFieldInt(COSEncryption.DK_Length, length);
 }
コード例 #6
0
 protected void initializeFromScratch() {
   COSEncryption encryption = getEncryption();
   encryption.cosSetField(COSEncryption.DK_V, COSInteger.create(getVersion()));
 }
コード例 #7
0
 public int getLength() {
   COSEncryption encryption = getEncryption();
   return encryption.getFieldInt(COSEncryption.DK_Length, DEFAULT_LENGTH);
 }