/// <summary> /// Create a new Sha256WithEcdsaSignature with a copy of the fields in the given /// signature object. /// </summary> /// /// <param name="signature">The signature object to copy.</param> public Sha256WithEcdsaSignature(Sha256WithEcdsaSignature signature) { this.signature_ = new Blob(); this.keyLocator_ = new ChangeCounter( new KeyLocator()); this.changeCount_ = 0; signature_ = signature.signature_; keyLocator_.set(new KeyLocator(signature.getKeyLocator())); }
/// <summary> /// Create a new Sha256WithEcdsaSignature with a copy of the fields in the given /// signature object. /// </summary> /// /// <param name="signature">The signature object to copy.</param> public Sha256WithEcdsaSignature(Sha256WithEcdsaSignature signature) { this.signature_ = new Blob(); this.keyLocator_ = new ChangeCounter( new KeyLocator()); this.validityPeriod_ = new ChangeCounter( new ValidityPeriod()); this.changeCount_ = 0; signature_ = signature.signature_; keyLocator_.set(new KeyLocator(signature.getKeyLocator())); }
/// <summary> /// Return a new Signature object based on the signature algorithm of the /// public key with keyName (derived from certificateName). /// </summary> /// /// <param name="certificateName">The certificate name.</param> /// <param name="digestAlgorithm"></param> /// <returns>A new object of the correct subclass of Signature.</returns> private Signature makeSignatureByCertificate(Name certificateName, DigestAlgorithm[] digestAlgorithm) { Name keyName = net.named_data.jndn.security.certificate.IdentityCertificate .certificateNameToPublicKeyName(certificateName); PublicKey publicKey = privateKeyStorage_.getPublicKey(keyName); KeyType keyType = publicKey.getKeyType(); if (keyType == net.named_data.jndn.security.KeyType.RSA) { Sha256WithRsaSignature signature = new Sha256WithRsaSignature(); digestAlgorithm[0] = net.named_data.jndn.security.DigestAlgorithm.SHA256; signature.getKeyLocator().setType(net.named_data.jndn.KeyLocatorType.KEYNAME); signature.getKeyLocator().setKeyName(certificateName.getPrefix(-1)); return signature; } else if (keyType == net.named_data.jndn.security.KeyType.ECDSA) { Sha256WithEcdsaSignature signature_0 = new Sha256WithEcdsaSignature(); digestAlgorithm[0] = net.named_data.jndn.security.DigestAlgorithm.SHA256; signature_0.getKeyLocator().setType(net.named_data.jndn.KeyLocatorType.KEYNAME); signature_0.getKeyLocator().setKeyName(certificateName.getPrefix(-1)); return signature_0; } else throw new SecurityException("Key type is not recognized"); }