Skip to content

Commit 7c5ed02

Browse files
committed
f - disallow Some(1) for quantity_max
1 parent 90a05ff commit 7c5ed02

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lightning/src/offers/offer.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,9 @@ pub enum Quantity {
431431
impl Quantity {
432432
fn new(quantity: Option<u64>) -> Self {
433433
match quantity {
434-
Some(1) | None => Quantity::One,
434+
None => Quantity::One,
435435
Some(0) => Quantity::Many,
436+
Some(1) => unreachable!(),
436437
Some(n) => Quantity::Max(NonZeroU64::new(n).unwrap()),
437438
}
438439
}
@@ -515,7 +516,10 @@ impl TryFrom<OfferTlvStream> for OfferContents {
515516
paths => paths,
516517
};
517518

518-
let supported_quantity = Quantity::new(quantity_max);
519+
let supported_quantity = match quantity_max {
520+
Some(1) => return Err(SemanticError::InvalidQuantity),
521+
_ => Quantity::new(quantity_max),
522+
};
519523

520524
if node_id.is_none() {
521525
return Err(SemanticError::MissingNodeId);

lightning/src/offers/parse.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ pub enum SemanticError {
8080
MissingNodeId,
8181
/// An empty set of blinded paths was provided.
8282
MissingPaths,
83+
/// An unsupported quantity was provided.
84+
InvalidQuantity,
8385
}
8486

8587
impl From<bech32::Error> for ParseError {

0 commit comments

Comments
 (0)