Skip to content

Commit 1355bf6

Browse files
committed
Merge pull request #40 from HeroicKatora/fix-interfaces
Soft fixes for broken interfaces
2 parents 753b998 + 92865a6 commit 1355bf6

File tree

6 files changed

+134
-36
lines changed

6 files changed

+134
-36
lines changed

.cirrus.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ nightly_task:
2222
cargo_cache:
2323
folder: $CARGO_HOME/registry
2424
fingerprint_script: cat Cargo.lock
25+
pre_script: cargo --version
2526
build_script: cargo build --no-default-features --features "rocket-frontend"
2627
test_script: cargo test --no-default-features --features "rocket-frontend"
2728
before_cache_script: rm -rf $CARGO_HOME/registry/index

Cargo.lock

Lines changed: 29 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ actix-web = { version = "0.7.17", optional = true }
2929
mime = { version = "0.3.13", optional = true }
3030
futures = { version = "0.1", optional = true }
3131
iron = { version = "0.6", optional = true }
32-
rocket = { version = "0.4.0", optional = true }
32+
rocket = { version = "0.4.2", optional = true }
3333
rouille = { version = "3.0", optional = true }
3434
router = { version = "0.6", optional = true }
3535
serde_urlencoded = { version = "0.5.1", optional = true }

src/primitives/generator.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,14 @@ impl Assertion {
126126
}
127127

128128
/// Construct an assertion instance whose tokens are only valid for the program execution.
129+
#[deprecated = "Use the correctly named `ephemeral` instead."]
130+
#[doc(hidden)]
129131
pub fn ephermal() -> Assertion {
132+
Self::ephemeral()
133+
}
134+
135+
/// Construct an assertion instance whose tokens are only valid for the program execution.
136+
pub fn ephemeral() -> Self {
130137
SigningKey::generate(&SHA256, &SystemRandom::new()).unwrap().into()
131138
}
132139

@@ -315,12 +322,15 @@ mod time_serde {
315322
impl SerdeAssertionGrant {
316323
fn try_from(grant: &Grant) -> Result<Self, ()> {
317324
let mut public_extensions: HashMap<String, Option<String>> = HashMap::new();
318-
if grant.extensions.iter_private().any(|_| true) {
325+
326+
if grant.extensions.private().any(|_| true) {
319327
return Err(())
320-
};
321-
for (name, content) in grant.extensions.iter_public() {
328+
}
329+
330+
for (name, content) in grant.extensions.public() {
322331
public_extensions.insert(name.to_string(), content.map(str::to_string));
323332
}
333+
324334
Ok(SerdeAssertionGrant {
325335
owner_id: grant.owner_id.clone(),
326336
client_id: grant.client_id.clone(),

src/primitives/grant.rs

Lines changed: 89 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl Extensions {
118118

119119
/// Set content for an extension without a corresponding instance.
120120
pub fn set_raw(&mut self, identifier: String, content: Value) {
121-
self.extensions.insert(identifier.to_string(), content);
121+
self.extensions.insert(identifier, content);
122122
}
123123

124124
/// Retrieve the stored data of an instance.
@@ -130,33 +130,73 @@ impl Extensions {
130130
}
131131

132132
/// Iterate of the public extensions whose presence and content is not secret.
133+
#[deprecated = "Use the simpler `public` instead."]
133134
pub fn iter_public(&self) -> PublicExtensions {
134-
PublicExtensions(self.extensions.iter())
135+
self.public()
136+
}
137+
138+
/// Iterate of the public extensions whose presence and content is not secret.
139+
pub fn public(&self) -> PublicExtensions {
140+
PublicExtensions { iter: self.extensions.iter(), private: false }
135141
}
136142

137143
/// Iterate of the private extensions whose presence and content must not be revealed.
144+
///
145+
/// Note: The return type is `PublicExtensions` by accident. This will be fixed in the next
146+
/// breaking release. The values yielded by the iterator are the private extensions, contrary
147+
/// to its name and short description.
148+
#[deprecated = "The method return type is incorrect. Use the `private` method instead,
149+
or `public` if you actually intended to iterate public extensions."]
138150
pub fn iter_private(&self) -> PublicExtensions {
139-
PublicExtensions(self.extensions.iter())
151+
PublicExtensions { iter: self.extensions.iter(), private: true }
152+
}
153+
154+
/// Iterate of the private extensions whose presence and content must not be revealed.
155+
pub fn private(&self) -> PrivateExtensions {
156+
PrivateExtensions(self.extensions.iter())
140157
}
141158
}
142159

143160
/// An iterator over the public extensions of a grant.
144-
pub struct PublicExtensions<'a>(Iter<'a, String, Value>);
161+
///
162+
/// Note: Due to an api bug that would require a breaking change, this type is also created with
163+
/// the [`Extensions::iter_private`][1] method. It will yield the private extensions in that case.
164+
/// This behaviour will be removed in the next breaking release.
165+
///
166+
/// [1]: struct.Extensions.html#method.iter_private
167+
pub struct PublicExtensions<'a> {
168+
iter: Iter<'a, String, Value>,
169+
/// FIXME: marker to simulate the `PrivateExtensions` instead. This avoids a breaking change,
170+
/// so remove this in the next major version.
171+
private: bool,
172+
}
145173

146174
/// An iterator over the private extensions of a grant.
147175
///
148176
/// Implementations which acquire an instance should take special not to leak any secrets to
149177
/// clients and third parties.
150178
pub struct PrivateExtensions<'a>(Iter<'a, String, Value>);
151179

180+
impl PublicExtensions<'_> {
181+
/// Check if this iterator was created with [`iter_private`] and iterates private extensions.
182+
///
183+
/// See the struct documentation for a note on why this method exists.
184+
#[deprecated = "This interface should not be required and will be removed."]
185+
pub fn is_private(&self) -> bool {
186+
self.private
187+
}
188+
}
189+
152190
impl<'a> Iterator for PublicExtensions<'a> {
153191
type Item = (&'a str, Option<&'a str>);
154192

155193
fn next(&mut self) -> Option<Self::Item> {
156194
loop {
157-
match self.0.next() {
195+
match self.iter.next() {
158196
None => return None,
159-
Some((key, Value::Public(content)))
197+
Some((key, Value::Public(content))) if !self.private
198+
=> return Some((key, content.as_ref().map(String::as_str))),
199+
Some((key, Value::Private(content))) if self.private
160200
=> return Some((key, content.as_ref().map(String::as_str))),
161201
_ => (),
162202
}
@@ -210,3 +250,46 @@ impl<T: GrantExtension + ?Sized> GrantExtension for Rc<T> {
210250
(**self).identifier()
211251
}
212252
}
253+
254+
#[cfg(test)]
255+
mod tests {
256+
use super::{Extensions, Value};
257+
258+
#[test]
259+
#[allow(deprecated)]
260+
fn iteration() {
261+
let mut extensions = Extensions::new();
262+
extensions.set_raw("pub".into(), Value::Public(Some("content".into())));
263+
extensions.set_raw("pub_none".into(), Value::Public(None));
264+
extensions.set_raw("priv".into(), Value::Private(Some("private".into())));
265+
extensions.set_raw("priv_none".into(), Value::Private(None));
266+
267+
assert_eq!(extensions.public()
268+
.filter(|&(name, value)| name == "pub" && value == Some("content"))
269+
.count(), 1);
270+
assert_eq!(extensions.iter_public()
271+
.filter(|&(name, value)| name == "pub" && value == Some("content"))
272+
.count(), 1);
273+
assert_eq!(extensions.public()
274+
.filter(|&(name, value)| name == "pub_none" && value == None)
275+
.count(), 1);
276+
assert_eq!(extensions.iter_public()
277+
.filter(|&(name, value)| name == "pub_none" && value == None)
278+
.count(), 1);
279+
assert_eq!(extensions.public().count(), 2);
280+
281+
assert_eq!(extensions.private()
282+
.filter(|&(name, value)| name == "priv" && value == Some("private"))
283+
.count(), 1);
284+
assert_eq!(extensions.iter_private()
285+
.filter(|&(name, value)| name == "priv" && value == Some("private"))
286+
.count(), 1);
287+
assert_eq!(extensions.private()
288+
.filter(|&(name, value)| name == "priv_none" && value == None)
289+
.count(), 1);
290+
assert_eq!(extensions.iter_private()
291+
.filter(|&(name, value)| name == "priv_none" && value == None)
292+
.count(), 1);
293+
assert_eq!(extensions.private().count(), 2);
294+
}
295+
}

src/primitives/issuer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ impl TokenSigner {
179179
/// .unwrap());
180180
/// ```
181181
pub fn ephemeral() -> TokenSigner {
182-
TokenSigner::new(Assertion::ephermal())
182+
TokenSigner::new(Assertion::ephemeral())
183183
}
184184

185185
/// Set the validity of all issued grants to the specified duration.

0 commit comments

Comments
 (0)