summaryrefslogtreecommitdiff
path: root/dhall
diff options
context:
space:
mode:
authorNadrieril2019-08-03 21:36:53 +0200
committerNadrieril2019-08-03 21:36:53 +0200
commit2ad5973a32099ad8f79f247adc9d03340e2df4ab (patch)
treedf68024b6e40208aeb4e697163f7a29576e1319f /dhall
parent3008f5711fbe40d1930ebc36e602c29d3fbec3eb (diff)
Update dhall-lang submodule
Diffstat (limited to '')
m---------dhall-lang0
-rw-r--r--dhall/src/phase/binary.rs24
-rw-r--r--dhall_syntax/Cargo.toml1
-rw-r--r--dhall_syntax/src/core/import.rs5
-rw-r--r--dhall_syntax/src/parser.rs18
-rw-r--r--dhall_syntax/src/printer.rs4
6 files changed, 31 insertions, 21 deletions
diff --git a/dhall-lang b/dhall-lang
-Subproject 8fff4cb42e6c4d1005205609957b785a3d11f8d
+Subproject 70c049883d2a6c9662511f166f5a359b7664d0d
diff --git a/dhall/src/phase/binary.rs b/dhall/src/phase/binary.rs
index 96eaa6c..1812131 100644
--- a/dhall/src/phase/binary.rs
+++ b/dhall/src/phase/binary.rs
@@ -196,17 +196,15 @@ fn cbor_value_to_dhall(
};
let hash = match hash {
Null => None,
- Array(vec) => match vec.as_slice() {
- [String(protocol), String(hash)] => Some(Hash {
- protocol: protocol.clone(),
- hash: hash.clone(),
- }),
- _ => Err(DecodeError::WrongFormatError(
- "import/hash".to_owned(),
- ))?,
+ Bytes(bytes) => match bytes.as_slice() {
+ [18, 32, rest..] => Some(Hash::SHA256(rest.to_vec())),
+ _ => Err(DecodeError::WrongFormatError(format!(
+ "import/hash/unknown_multihash: {:?}",
+ bytes
+ )))?,
},
_ => Err(DecodeError::WrongFormatError(
- "import/hash".to_owned(),
+ "import/hash/should_be_bytes".to_owned(),
))?,
};
let mut rest = rest.iter();
@@ -518,7 +516,7 @@ fn serialize_import<S>(ser: S, import: &Import) -> Result<S::Ok, S::Error>
where
S: serde::ser::Serializer,
{
- use cbor::Value::{Array, Null, String, U64};
+ use cbor::Value::{Bytes, Null, U64};
use serde::ser::SerializeSeq;
let count = 4 + match &import.location_hashed.location {
@@ -533,8 +531,10 @@ where
let hash = match &import.location_hashed.hash {
None => Null,
- Some(h) => {
- Array(vec![String(h.protocol.clone()), String(h.hash.clone())])
+ Some(Hash::SHA256(h)) => {
+ let mut bytes = vec![18, 32];
+ bytes.extend_from_slice(h);
+ Bytes(bytes)
}
};
ser_seq.serialize_element(&hash)?;
diff --git a/dhall_syntax/Cargo.toml b/dhall_syntax/Cargo.toml
index b25a0fe..6a61b09 100644
--- a/dhall_syntax/Cargo.toml
+++ b/dhall_syntax/Cargo.toml
@@ -14,5 +14,6 @@ percent-encoding = "1.0.1"
pest = "2.1"
either = "1.5.2"
take_mut = "0.2.2"
+hex = "0.3.2"
dhall_generated_parser = { path = "../dhall_generated_parser" }
improved_slice_patterns = { version = "2.0.0", path = "../improved_slice_patterns" }
diff --git a/dhall_syntax/src/core/import.rs b/dhall_syntax/src/core/import.rs
index fbf2f7b..c328e34 100644
--- a/dhall_syntax/src/core/import.rs
+++ b/dhall_syntax/src/core/import.rs
@@ -43,9 +43,8 @@ pub enum ImportMode {
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
-pub struct Hash {
- pub protocol: String,
- pub hash: String,
+pub enum Hash {
+ SHA256(Vec<u8>),
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
diff --git a/dhall_syntax/src/parser.rs b/dhall_syntax/src/parser.rs
index 316ef2f..d8bd957 100644
--- a/dhall_syntax/src/parser.rs
+++ b/dhall_syntax/src/parser.rs
@@ -461,6 +461,11 @@ make_parser! {
lines.push(vec![]);
lines
},
+ [single_quote_char("\r\n"), single_quote_continue(lines)] => {
+ let mut lines = lines;
+ lines.push(vec![]);
+ lines
+ },
[single_quote_char(c), single_quote_continue(lines)] => {
// TODO: don't allocate for every char
let c = InterpolatedTextContents::Text(c.to_owned());
@@ -654,12 +659,15 @@ make_parser! {
},
));
- rule!(hash<Hash>; captured_str!(s) =>
- Hash {
- protocol: s.trim()[..6].to_owned(),
- hash: s.trim()[7..].to_owned(),
+ rule!(hash<Hash>; captured_str!(s) => {
+ let s = s.trim();
+ let protocol = &s[..6];
+ let hash = &s[7..];
+ if protocol != "sha256" {
+ Err(format!("Unknown hashing protocol '{}'", protocol))?
}
- );
+ Hash::SHA256(hex::decode(hash).unwrap())
+ });
rule!(import_hashed<ImportHashed>; children!(
[import_type(location)] =>
diff --git a/dhall_syntax/src/printer.rs b/dhall_syntax/src/printer.rs
index f1ce230..dbed55d 100644
--- a/dhall_syntax/src/printer.rs
+++ b/dhall_syntax/src/printer.rs
@@ -348,7 +348,9 @@ impl Display for Label {
impl Display for Hash {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
- write!(f, "{}:{}", self.protocol, self.hash)
+ match self {
+ Hash::SHA256(hash) => write!(f, "sha256:{}", hex::encode(hash)),
+ }
}
}
impl Display for ImportHashed {