Skip to content

Commit 26f2629

Browse files
committed
Make to_point_poly more flexible
1 parent 6abb5e7 commit 26f2629

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## UNRELEASED
44

5+
- Change `poly::scalar::to_point_poly` to make it less opinionated
56
- Add From/TryFrom conversions for `Scalar` to all unsigned integer types
67
- Upgrade to bincode v2
78
- MSRV 1.63 -> 1.85

secp256kfun/src/point.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ impl<T, S, Z> AsRef<backend::Point> for Point<T, S, Z> {
7979
}
8080
}
8181

82+
impl<T, S, Z> AsRef<Point<T, S, Z>> for Point<T, S, Z> {
83+
fn as_ref(&self) -> &Point<T, S, Z> {
84+
self
85+
}
86+
}
87+
8288
impl<T: Copy, S, Z> Copy for Point<T, S, Z> {}
8389

8490
impl Point<Normal, Public, NonZero> {

secp256kfun/src/poly.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,13 @@ pub mod scalar {
3535
/// .collect::<Vec<_>>();
3636
/// let point_poly = poly::scalar::to_point_poly(&secret_poly);
3737
/// ```
38-
pub fn to_point_poly(scalar_poly: &[Scalar]) -> Vec<Point> {
39-
scalar_poly.iter().map(|a| g!(a * G).normalize()).collect()
38+
pub fn to_point_poly<S: Secrecy, Z: ZeroChoice>(
39+
scalar_poly: impl IntoIterator<Item = impl AsRef<Scalar<S, Z>>>,
40+
) -> Vec<Point<Normal, Public, Z>> {
41+
scalar_poly
42+
.into_iter()
43+
.map(|a| g!(a.as_ref() * G).normalize())
44+
.collect()
4045
}
4146

4247
/// Generate a [`Scalar`] polynomial with `length` coefficients.

secp256kfun/src/scalar.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ impl<S, Z> AsRef<backend::Scalar> for Scalar<S, Z> {
5959
}
6060
}
6161

62+
impl<S, Z> AsRef<Scalar<S, Z>> for Scalar<S, Z> {
63+
fn as_ref(&self) -> &Scalar<S, Z> {
64+
self
65+
}
66+
}
67+
6268
impl<S, Z> Clone for Scalar<S, Z> {
6369
fn clone(&self) -> Self {
6470
*self

0 commit comments

Comments
 (0)