move comments before attributes; make gencode handle them (#280)
This commit is contained in:
parent
850381fe24
commit
b829d4ff9f
|
@ -19,8 +19,8 @@ mod tests;
|
|||
/// An error.
|
||||
pub type Error = frost_core::Error<Ed25519Sha512>;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
/// An implementation of the FROST(Ed25519, SHA-512) ciphersuite scalar field.
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct Ed25519ScalarField;
|
||||
|
||||
impl Field for Ed25519ScalarField {
|
||||
|
@ -66,8 +66,8 @@ impl Field for Ed25519ScalarField {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
/// An implementation of the FROST(Ed25519, SHA-512) ciphersuite group.
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
pub struct Ed25519Group;
|
||||
|
||||
impl Group for Ed25519Group {
|
||||
|
@ -141,8 +141,8 @@ fn hash_to_scalar(inputs: &[&[u8]]) -> Scalar {
|
|||
/// [spec]: https://www.ietf.org/archive/id/draft-irtf-cfrg-frost-11.html#section-6.1-1
|
||||
const CONTEXT_STRING: &str = "FROST-ED25519-SHA512-v11";
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
/// An implementation of the FROST(Ed25519, SHA-512) ciphersuite.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
pub struct Ed25519Sha512;
|
||||
|
||||
impl Ciphersuite for Ed25519Sha512 {
|
||||
|
|
|
@ -20,8 +20,8 @@ mod tests;
|
|||
/// An error.
|
||||
pub type Error = frost_core::Error<Ed448Shake256>;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
/// An implementation of the FROST(Ed448, SHAKE256) ciphersuite scalar field.
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct Ed448ScalarField;
|
||||
|
||||
impl Field for Ed448ScalarField {
|
||||
|
@ -65,8 +65,8 @@ impl Field for Ed448ScalarField {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
/// An implementation of the FROST(Ed448, SHAKE256) ciphersuite group.
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
pub struct Ed448Group;
|
||||
|
||||
impl Group for Ed448Group {
|
||||
|
@ -136,8 +136,8 @@ fn hash_to_scalar(inputs: &[&[u8]]) -> Scalar {
|
|||
/// [spec]: https://www.ietf.org/archive/id/draft-irtf-cfrg-frost-11.html#section-6.3-1
|
||||
const CONTEXT_STRING: &str = "FROST-ED448-SHAKE256-v11";
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
/// An implementation of the FROST(Ed448, SHAKE256) ciphersuite.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
pub struct Ed448Shake256;
|
||||
|
||||
impl Ciphersuite for Ed448Shake256 {
|
||||
|
|
|
@ -21,8 +21,8 @@ mod tests;
|
|||
/// An error.
|
||||
pub type Error = frost_core::Error<P256Sha256>;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
/// An implementation of the FROST(P-256, SHA-256) ciphersuite scalar field.
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct P256ScalarField;
|
||||
|
||||
impl Field for P256ScalarField {
|
||||
|
@ -71,8 +71,8 @@ impl Field for P256ScalarField {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
/// An implementation of the FROST(P-256, SHA-256) ciphersuite group.
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
pub struct P256Group;
|
||||
|
||||
impl Group for P256Group {
|
||||
|
@ -161,8 +161,8 @@ fn hash_to_scalar(domain: &[u8], msg: &[u8]) -> Scalar {
|
|||
/// [spec]: https://www.ietf.org/archive/id/draft-irtf-cfrg-frost-11.html#section-6.4-1
|
||||
const CONTEXT_STRING: &str = "FROST-P256-SHA256-v11";
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
/// An implementation of the FROST(P-256, SHA-256) ciphersuite.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
pub struct P256Sha256;
|
||||
|
||||
impl Ciphersuite for P256Sha256 {
|
||||
|
|
|
@ -19,8 +19,8 @@ mod tests;
|
|||
/// An error.
|
||||
pub type Error = frost_core::Error<Ristretto255Sha512>;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
/// An implementation of the FROST(ristretto255, SHA-512) ciphersuite scalar field.
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct RistrettoScalarField;
|
||||
|
||||
impl Field for RistrettoScalarField {
|
||||
|
@ -66,8 +66,8 @@ impl Field for RistrettoScalarField {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
/// An implementation of the FROST(ristretto255, SHA-512) ciphersuite group.
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
pub struct RistrettoGroup;
|
||||
|
||||
impl Group for RistrettoGroup {
|
||||
|
@ -130,8 +130,8 @@ fn hash_to_scalar(inputs: &[&[u8]]) -> Scalar {
|
|||
/// [spec]: https://www.ietf.org/archive/id/draft-irtf-cfrg-frost-11.html#section-6.2-1
|
||||
const CONTEXT_STRING: &str = "FROST-RISTRETTO255-SHA512-v11";
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
/// An implementation of the FROST(ristretto255, SHA-512) ciphersuite.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
pub struct Ristretto255Sha512;
|
||||
|
||||
impl Ciphersuite for Ristretto255Sha512 {
|
||||
|
|
|
@ -22,8 +22,8 @@ mod tests;
|
|||
/// An error.
|
||||
pub type Error = frost_core::Error<Secp256K1Sha256>;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
/// An implementation of the FROST(secp256k1, SHA-256) ciphersuite scalar field.
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct Secp256K1ScalarField;
|
||||
|
||||
impl Field for Secp256K1ScalarField {
|
||||
|
@ -71,8 +71,8 @@ impl Field for Secp256K1ScalarField {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
/// An implementation of the FROST(secp256k1, SHA-256) ciphersuite group.
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
pub struct Secp256K1Group;
|
||||
|
||||
impl Group for Secp256K1Group {
|
||||
|
@ -162,8 +162,8 @@ fn hash_to_scalar(domain: &[u8], msg: &[u8]) -> Scalar {
|
|||
/// [spec]: https://www.ietf.org/archive/id/draft-irtf-cfrg-frost-11.html#section-6.5-1
|
||||
const CONTEXT_STRING: &str = "FROST-secp256k1-SHA256-v11";
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
/// An implementation of the FROST(secp256k1, SHA-256) ciphersuite.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
pub struct Secp256K1Sha256;
|
||||
|
||||
impl Ciphersuite for Secp256K1Sha256 {
|
||||
|
|
|
@ -45,12 +45,26 @@ use regex::Regex;
|
|||
fn read_docs(filename: &str, suite_strings: &[&str]) -> Vec<(String, String, usize, usize)> {
|
||||
let mut docs = Vec::new();
|
||||
let code = fs::read_to_string(filename).unwrap();
|
||||
let re = Regex::new(r"(?m)((^[ ]*///.*\n)+)\s*pub (.*)").unwrap();
|
||||
let re = Regex::new(concat!(
|
||||
// Enable multi-line (makes "^" match start of line)
|
||||
r"(?m)",
|
||||
// Matches multiple comment lines: whitespace, three slashes, anything else.
|
||||
// Captures the entire comment in the "doc" group.
|
||||
r"(?P<doc>(^[ ]*///.*\n)+)",
|
||||
// Matches zero or more attributes: whitespace, "#", anything else.
|
||||
// Captures all attributes in the "attrs" group
|
||||
r"(?P<attrs>(\s*#.*\n)*)",
|
||||
// Matches the item declaration: whitespace, "pub ", anything else (which
|
||||
// is captured in the "name" capture group)
|
||||
r"\s*pub (?P<name>.*)"
|
||||
))
|
||||
.unwrap();
|
||||
|
||||
for m in re.captures_iter(code.as_str()) {
|
||||
// Captures: 0 - the whole match; 1: documentation;
|
||||
// 2: internal capture group; 3: the item "name" as described above
|
||||
let (name, doc) = (m.get(3).unwrap().as_str(), m.get(1).unwrap().as_str());
|
||||
let (name, doc) = (
|
||||
m.name("name").unwrap().as_str(),
|
||||
m.name("doc").unwrap().as_str(),
|
||||
);
|
||||
let mut name = name.to_string();
|
||||
// Replacing ciphersuite-specific names with a fixed string allows
|
||||
// comparing item "names" to check later if we're working on the
|
||||
|
@ -61,8 +75,8 @@ fn read_docs(filename: &str, suite_strings: &[&str]) -> Vec<(String, String, usi
|
|||
docs.push((
|
||||
name,
|
||||
doc.to_string(),
|
||||
m.get(1).unwrap().start(),
|
||||
m.get(1).unwrap().end(),
|
||||
m.name("doc").unwrap().start(),
|
||||
m.name("doc").unwrap().end(),
|
||||
))
|
||||
}
|
||||
docs
|
||||
|
@ -91,13 +105,11 @@ fn write_docs(
|
|||
|
||||
// To be able to replace the documentation properly, start from the end, which
|
||||
// will keep the string positions consistent
|
||||
for ((_old_name, _, old_start, old_end), (_new_name, new_doc, _, _)) in
|
||||
for ((old_name, _, old_start, old_end), (new_name, new_doc, _, _)) in
|
||||
zip(old_docs.iter().rev(), docs.iter().rev())
|
||||
{
|
||||
// This is a sanity check to test if we're replacing the right comment.
|
||||
// It was commented out due to an exception (Ed25519 scalar is defined
|
||||
// as the Ristretto25519 scalar instead of its own struct)
|
||||
// assert_eq!(old_name, new_name, "source code does not match");
|
||||
assert_eq!(old_name, new_name, "source code does not match");
|
||||
|
||||
// Replaces ciphersuite-references in documentation
|
||||
let mut new_doc = new_doc.to_string();
|
||||
|
|
Loading…
Reference in New Issue