Parcourir la source

Reject invalid tag combinations for TaggedIdent

Ian Goldberg il y a 4 mois
Parent
commit
cbb021612f
2 fichiers modifiés avec 9 ajouts et 1 suppressions
  1. 4 0
      Cargo.toml
  2. 5 1
      sigma_compiler_core/src/syntax.rs

+ 4 - 0
Cargo.toml

@@ -5,3 +5,7 @@ edition = "2021"
 
 [dependencies]
 sigma_compiler_derive = { path = "sigma_compiler_derive" }
+
+[dev-dependencies]
+curve25519-dalek = { version = "4", features = [ "group", "rand_core", "digest" ] }
+group = "0.13"

+ 5 - 1
sigma_compiler_core/src/syntax.rs

@@ -2,7 +2,7 @@ use quote::format_ident;
 use syn::ext::IdentExt;
 use syn::parse::{Parse, ParseStream, Result};
 use syn::punctuated::Punctuated;
-use syn::{parenthesized, Expr, Ident, Token};
+use syn::{parenthesized, Error, Expr, Ident, Token};
 
 /// A `TaggedIdent` is an `Ident`, preceded by zero or more of the
 /// following tags: `pub`, `rand`, `cind`, `const`, `vec`
@@ -61,6 +61,10 @@ impl TaggedIdent {
                 "const" if point => {
                     is_const = true;
                 }
+                // any other use of the above keywords is not allowed
+                "pub" | "rand" | "cind" | "const" => {
+                    return Err(Error::new(id.span(), "tag not allowed in this position"));
+                }
                 // vec is allowed with either Scalars or Points, and
                 // with any other tag
                 "vec" => {