mirror of
https://github.com/torproject/metrics-lib.git
synced 2024-11-23 01:09:47 +00:00
Provide microdescriptor digest in hex encoding.
This commit is contained in:
parent
ff7e36c156
commit
664921eb50
@ -7,6 +7,9 @@
|
||||
* Medium changes
|
||||
- Optimize parsing of large files containing many descriptors.
|
||||
|
||||
* Minor changes
|
||||
- Provide microdescriptor SHA-256 digest in hexadecimal encoding.
|
||||
|
||||
|
||||
# Changes in version 2.14.0 - 2020-08-07
|
||||
|
||||
|
@ -32,6 +32,15 @@ public interface Microdescriptor extends Descriptor {
|
||||
*/
|
||||
String getDigestSha256Base64();
|
||||
|
||||
/**
|
||||
* Return the SHA-256 descriptor digest, encoded as 64 lower-case hexadecimal
|
||||
* characters, that can be used as file name when writing this descriptor to
|
||||
* disk.
|
||||
*
|
||||
* @since 2.15.0
|
||||
*/
|
||||
String getDigestSha256Hex();
|
||||
|
||||
/**
|
||||
* Return the RSA-1024 public key in PEM format used to encrypt CREATE
|
||||
* cells for this server, or null if the descriptor doesn't contain an
|
||||
|
@ -6,6 +6,9 @@ package org.torproject.descriptor.impl;
|
||||
import org.torproject.descriptor.DescriptorParseException;
|
||||
import org.torproject.descriptor.Microdescriptor;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.codec.binary.Hex;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -26,6 +29,7 @@ public class MicrodescriptorImpl extends DescriptorImpl
|
||||
super(descriptorBytes, offsetAndLength, descriptorFile, false);
|
||||
this.parseDescriptorBytes();
|
||||
this.calculateDigestSha256Base64(Key.ONION_KEY.keyword + NL);
|
||||
this.convertDigestSha256Base64ToHex();
|
||||
this.checkExactlyOnceKeys(EnumSet.of(Key.ONION_KEY));
|
||||
Set<Key> atMostOnceKeys = EnumSet.of(
|
||||
Key.NTOR_ONION_KEY, Key.FAMILY, Key.P, Key.P6, Key.ID);
|
||||
@ -212,6 +216,18 @@ public class MicrodescriptorImpl extends DescriptorImpl
|
||||
}
|
||||
}
|
||||
|
||||
private void convertDigestSha256Base64ToHex() {
|
||||
this.digestSha256Hex = Hex.encodeHexString(Base64.decodeBase64(
|
||||
this.getDigestSha256Base64()));
|
||||
}
|
||||
|
||||
private String digestSha256Hex;
|
||||
|
||||
@Override
|
||||
public String getDigestSha256Hex() {
|
||||
return this.digestSha256Hex;
|
||||
}
|
||||
|
||||
private String onionKey;
|
||||
|
||||
@Override
|
||||
|
@ -74,6 +74,9 @@ public class MicrodescriptorImplTest {
|
||||
Microdescriptor micro = DescriptorBuilder.createWithDefaultLines();
|
||||
assertEquals("ER1AC4KqT//o3pJDrqlmej5G2qW1EQYEr/IrMQHNc6I",
|
||||
micro.getDigestSha256Base64());
|
||||
assertEquals(
|
||||
"111d400b82aa4fffe8de9243aea9667a3e46daa5b5110604aff22b3101cd73a2",
|
||||
micro.getDigestSha256Hex());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user