diff --git a/app/specs/guests/snapshot/snapshot.json b/app/specs/guests/snapshot/snapshot.json new file mode 100644 index 00000000..48957743 --- /dev/null +++ b/app/specs/guests/snapshot/snapshot.json @@ -0,0 +1,19 @@ +{ + "id": "snapshot", + "wasm": "site/snapshot/guest/snapshot.wasm", + "pin": "site/snapshot/guest.mjs", + "modules": [ + "PrismSnapshot" + ], + "dispatch": "PrismSnapshot::prismSnapshotDispatch", + "vectors": "spec:snapshot", + "limits": [ + 2048, + 512, + 4096 + ], + "memory": [ + 2048, + 1048576 + ] +} diff --git a/app/specs/guests/snapshot/snapshot.lock.json b/app/specs/guests/snapshot/snapshot.lock.json new file mode 100644 index 00000000..2fa21c6d --- /dev/null +++ b/app/specs/guests/snapshot/snapshot.lock.json @@ -0,0 +1,4 @@ +{ + "source": "04f0ba50de79f2d0cc6090edd1250cf3750847a85e12587739e7912e86cd33d5", + "wasm": "041b56c0ddcb4a2525259b4e03dbb6de493832e4903bb3d59f3ae03c6db39768" +} diff --git a/app/specs/parts/spec.json b/app/specs/parts/spec.json index af54431a..057d102d 100644 --- a/app/specs/parts/spec.json +++ b/app/specs/parts/spec.json @@ -335,6 +335,14 @@ ], "site/prov/guest.mjs": [ "how" + ], + "app/src/PrismSnapshot.lex.tex": [ + "why", + "when", + "how" + ], + "site/snapshot/guest.mjs": [ + "how" ] } } diff --git a/app/specs/snapshot/spec.json b/app/specs/snapshot/spec.json new file mode 100644 index 00000000..9b0d40d8 --- /dev/null +++ b/app/specs/snapshot/spec.json @@ -0,0 +1,96 @@ +{"name":"snapshot","comment":"The acceptance vectors of the snapshot guest (app/src/PrismSnapshot.lex.tex), written from the oracles under app/specs/oracle by the snapshotvectors step of generators/snapshot/steps.json, which says what each one is.","examples":[ +["apply\n[{\"q\":{\"bar\":2}},[{\"op\":\"add\",\"path\":\"/a/b\",\"value\":1}]]","the patch does not apply"], +["apply\n[{\"foo\":\"bar\"},[{\"op\":\"add\",\"path\":\"/baz\",\"value\":\"qux\"}]]","{\"baz\":\"qux\",\"foo\":\"bar\"}"], +["apply\n[{\"foo\":[\"bar\",\"baz\"]},[{\"op\":\"add\",\"path\":\"/foo/1\",\"value\":\"qux\"}]]","{\"foo\":[\"bar\",\"qux\",\"baz\"]}"], +["apply\n[{\"baz\":\"qux\",\"foo\":\"bar\"},[{\"op\":\"remove\",\"path\":\"/baz\"}]]","{\"foo\":\"bar\"}"], +["apply\n[{\"foo\":[\"bar\",\"qux\",\"baz\"]},[{\"op\":\"remove\",\"path\":\"/foo/1\"}]]","{\"foo\":[\"bar\",\"baz\"]}"], +["apply\n[{\"baz\":\"qux\",\"foo\":\"bar\"},[{\"op\":\"replace\",\"path\":\"/baz\",\"value\":\"boo\"}]]","{\"baz\":\"boo\",\"foo\":\"bar\"}"], +["apply\n[{\"foo\":{\"bar\":\"baz\",\"waldo\":\"fred\"},\"qux\":{\"corge\":\"grault\"}},[{\"op\":\"move\",\"from\":\"/foo/waldo\",\"path\":\"/qux/thud\"}]]","{\"foo\":{\"bar\":\"baz\"},\"qux\":{\"corge\":\"grault\",\"thud\":\"fred\"}}"], +["apply\n[{\"foo\":[\"all\",\"grass\",\"cows\",\"eat\"]},[{\"op\":\"move\",\"from\":\"/foo/1\",\"path\":\"/foo/3\"}]]","{\"foo\":[\"all\",\"cows\",\"eat\",\"grass\"]}"], +["apply\n[{\"baz\":\"qux\",\"foo\":[\"a\",2,\"c\"]},[{\"op\":\"test\",\"path\":\"/baz\",\"value\":\"qux\"},{\"op\":\"test\",\"path\":\"/foo/1\",\"value\":2}]]","{\"baz\":\"qux\",\"foo\":[\"a\",2,\"c\"]}"], +["apply\n[{\"baz\":\"qux\"},[{\"op\":\"test\",\"path\":\"/baz\",\"value\":\"bar\"}]]","the patch does not apply"], +["apply\n[{\"foo\":\"bar\"},[{\"op\":\"add\",\"path\":\"/child\",\"value\":{\"grandchild\":{}}}]]","{\"child\":{\"grandchild\":{}},\"foo\":\"bar\"}"], +["apply\n[{\"foo\":\"bar\"},[{\"op\":\"add\",\"path\":\"/baz\",\"value\":\"qux\",\"xyz\":123}]]","{\"baz\":\"qux\",\"foo\":\"bar\"}"], +["apply\n[{\"foo\":\"bar\"},[{\"op\":\"add\",\"path\":\"/baz/bat\",\"value\":\"qux\"}]]","the patch does not apply"], +["apply\n[{\"foo\":\"bar\"},[{\"op\":\"add\",\"path\":\"/baz\",\"value\":\"qux\",\"op\":\"remove\"}]]","the patch does not apply"], +["apply\n[{\"/\":9,\"~1\":10},[{\"op\":\"test\",\"path\":\"/~01\",\"value\":10}]]","{\"/\":9,\"~1\":10}"], +["apply\n[{\"/\":9,\"~1\":10},[{\"op\":\"test\",\"path\":\"/~01\",\"value\":\"10\"}]]","the patch does not apply"], +["apply\n[{\"foo\":[\"bar\"]},[{\"op\":\"add\",\"path\":\"/foo/-\",\"value\":[\"abc\",\"def\"]}]]","{\"foo\":[\"bar\",[\"abc\",\"def\"]]}"], +["canonical\n[\n 56,\n {\n \"d\": true,\n \"10\": null,\n \"1\": [ ]\n }\n]\n","[56,{\"1\":[],\"10\":null,\"d\":true}]"], +["address\n[\n 56,\n {\n \"d\": true,\n \"10\": null,\n \"1\": [ ]\n }\n]\n","sha256:099601b171cafed97c333f8878d68e7f8c8f795412adb34b2fdcf0e7c7beac42"], +["canonical\n{\n \"peach\": \"This sorting order\",\n \"péché\": \"is wrong according to French\",\n \"pêche\": \"but canonicalization MUST\",\n \"sin\": \"ignore locale\"\n}\n","{\"peach\":\"This sorting order\",\"péché\":\"is wrong according to French\",\"pêche\":\"but canonicalization MUST\",\"sin\":\"ignore locale\"}"], +["address\n{\n \"peach\": \"This sorting order\",\n \"péché\": \"is wrong according to French\",\n \"pêche\": \"but canonicalization MUST\",\n \"sin\": \"ignore locale\"\n}\n","sha256:d99d0ebdcb0033cb858cfa830ae46bc0fb3309413b271f1da828c89901a27ed5"], +["canonical\n{\n \"1\": {\"f\": {\"f\": \"hi\",\"F\": 5} ,\"\\n\": 56.0},\n \"10\": { },\n \"\": \"empty\",\n \"a\": { },\n \"111\": [ {\"e\": \"yes\",\"E\": \"no\" } ],\n \"A\": { }\n}","{\"\":\"empty\",\"1\":{\"\\n\":56,\"f\":{\"F\":5,\"f\":\"hi\"}},\"10\":{},\"111\":[{\"E\":\"no\",\"e\":\"yes\"}],\"A\":{},\"a\":{}}"], +["address\n{\n \"1\": {\"f\": {\"f\": \"hi\",\"F\": 5} ,\"\\n\": 56.0},\n \"10\": { },\n \"\": \"empty\",\n \"a\": { },\n \"111\": [ {\"e\": \"yes\",\"E\": \"no\" } ],\n \"A\": { }\n}","sha256:605f65004ec2db7692522a0852c22f1c989e036d547e88963d1a3143cf3195d5"], +["canonical\n{\n \"Unnormalized Unicode\":\"A\\u030a\"\n}\n","{\"Unnormalized Unicode\":\"Å\"}"], +["address\n{\n \"Unnormalized Unicode\":\"A\\u030a\"\n}\n","sha256:0d99aad92a125196ff887876643fd3206786a84ddce2cee52ba4ad256d2381d3"], +["canonical\n{\n \"numbers\": [333333333.33333329, 1E30, 4.50, 2e-3, 0.000000000000000000000000001],\n \"string\": \"\\u20ac$\\u000F\\u000aA'\\u0042\\u0022\\u005c\\\\\\\"\\/\",\n \"literals\": [null, true, false]\n}","{\"literals\":[null,true,false],\"numbers\":[333333333.3333333,1e+30,4.5,0.002,1e-27],\"string\":\"€$\\u000f\\nA'B\\\"\\\\\\\\\\\"/\"}"], +["address\n{\n \"numbers\": [333333333.33333329, 1E30, 4.50, 2e-3, 0.000000000000000000000000001],\n \"string\": \"\\u20ac$\\u000F\\u000aA'\\u0042\\u0022\\u005c\\\\\\\"\\/\",\n \"literals\": [null, true, false]\n}","sha256:2d5e01a318d0f0879ab568c4be289c8b1f64ef8921a53c6277d5e069978baacb"], +["canonical\n{\n \"\\u20ac\": \"Euro Sign\",\n \"\\r\": \"Carriage Return\",\n \"\\u000a\": \"Newline\",\n \"1\": \"One\",\n \"\\u0080\": \"Control\\u007f\",\n \"\\ud83d\\ude02\": \"Smiley\",\n \"\\u00f6\": \"Latin Small Letter O With Diaeresis\",\n \"\\ufb33\": \"Hebrew Letter Dalet With Dagesh\",\n \"\": \"Browser Challenge\"\n}\n","{\"\\n\":\"Newline\",\"\\r\":\"Carriage Return\",\"1\":\"One\",\"\":\"Browser Challenge\",\"€\":\"Control\",\"ö\":\"Latin Small Letter O With Diaeresis\",\"€\":\"Euro Sign\",\"😂\":\"Smiley\",\"דּ\":\"Hebrew Letter Dalet With Dagesh\"}"], +["address\n{\n \"\\u20ac\": \"Euro Sign\",\n \"\\r\": \"Carriage Return\",\n \"\\u000a\": \"Newline\",\n \"1\": \"One\",\n \"\\u0080\": \"Control\\u007f\",\n \"\\ud83d\\ude02\": \"Smiley\",\n \"\\u00f6\": \"Latin Small Letter O With Diaeresis\",\n \"\\ufb33\": \"Hebrew Letter Dalet With Dagesh\",\n \"\": \"Browser Challenge\"\n}\n","sha256:6af595a9aa80110b964b4de3f82a05fa6ae7423005019bacfa2620dddc4e94d1"], +["sha256\nLen = 0\nMsg = 00","MD = e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"], +["sha256\nLen = 8\nMsg = d3","MD = 28969cdfa74a12c82f3bad960b0b000aca2ac329deea5c2328ebc6f2ba9802c1"], +["sha256\nLen = 16\nMsg = 11af","MD = 5ca7133fa735326081558ac312c620eeca9970d1e70a4b95533d956f072d1f98"], +["sha256\nLen = 24\nMsg = b4190e","MD = dff2e73091f6c05e528896c4c831b9448653dc2ff043528f6769437bc7b975c2"], +["sha256\nLen = 32\nMsg = 74ba2521","MD = b16aa56be3880d18cd41e68384cf1ec8c17680c45a02b1575dc1518923ae8b0e"], +["sha256\nLen = 40\nMsg = c299209682","MD = f0887fe961c9cd3beab957e8222494abb969b1ce4c6557976df8b0f6d20e9166"], +["sha256\nLen = 48\nMsg = e1dc724d5621","MD = eca0a060b489636225b4fa64d267dabbe44273067ac679f20820bddc6b6a90ac"], +["sha256\nLen = 56\nMsg = 06e076f5a442d5","MD = 3fd877e27450e6bbd5d74bb82f9870c64c66e109418baa8e6bbcff355e287926"], +["sha256\nLen = 64\nMsg = 5738c929c4f4ccb6","MD = 963bb88f27f512777aab6c8b1a02c70ec0ad651d428f870036e1917120fb48bf"], +["sha256\nLen = 72\nMsg = 3334c58075d3f4139e","MD = 078da3d77ed43bd3037a433fd0341855023793f9afd08b4b08ea1e5597ceef20"], +["sha256\nLen = 80\nMsg = 74cb9381d89f5aa73368","MD = 73d6fad1caaa75b43b21733561fd3958bdc555194a037c2addec19dc2d7a52bd"], +["sha256\nLen = 88\nMsg = 76ed24a0f40a41221ebfcf","MD = 044cef802901932e46dc46b2545e6c99c0fc323a0ed99b081bda4216857f38ac"], +["sha256\nLen = 96\nMsg = 9baf69cba317f422fe26a9a0","MD = fe56287cd657e4afc50dba7a3a54c2a6324b886becdcd1fae473b769e551a09b"], +["sha256\nLen = 104\nMsg = 68511cdb2dbbf3530d7fb61cbc","MD = af53430466715e99a602fc9f5945719b04dd24267e6a98471f7a7869bd3b4313"], +["sha256\nLen = 112\nMsg = af397a8b8dd73ab702ce8e53aa9f","MD = d189498a3463b18e846b8ab1b41583b0b7efc789dad8a7fb885bbf8fb5b45c5c"], +["sha256\nLen = 120\nMsg = 294af4802e5e925eb1c6cc9c724f09","MD = dcbaf335360de853b9cddfdafb90fa75567d0d3d58af8db9d764113aef570125"], +["sha256\nLen = 128\nMsg = 0a27847cdc98bd6f62220b046edd762b","MD = 80c25ec1600587e7f28b18b1b18e3cdc89928e39cab3bc25e4d4a4c139bcedc4"], +["sha256\nLen = 136\nMsg = 1b503fb9a73b16ada3fcf1042623ae7610","MD = d5c30315f72ed05fe519a1bf75ab5fd0ffec5ac1acb0daf66b6b769598594509"], +["sha256\nLen = 144\nMsg = 59eb45bbbeb054b0b97334d53580ce03f699","MD = 32c38c54189f2357e96bd77eb00c2b9c341ebebacc2945f97804f59a93238288"], +["sha256\nLen = 152\nMsg = 58e5a3259cb0b6d12c83f723379e35fd298b60","MD = 9b5b37816de8fcdf3ec10b745428708df8f391c550ea6746b2cafe019c2b6ace"], +["sha256\nLen = 160\nMsg = c1ef39cee58e78f6fcdc12e058b7f902acd1a93b","MD = 6dd52b0d8b48cc8146cebd0216fbf5f6ef7eeafc0ff2ff9d1422d6345555a142"], +["sha256\nLen = 168\nMsg = 9cab7d7dcaec98cb3ac6c64dd5d4470d0b103a810c","MD = 44d34809fc60d1fcafa7f37b794d1d3a765dd0d23194ebbe340f013f0c39b613"], +["sha256\nLen = 176\nMsg = ea157c02ebaf1b22de221b53f2353936d2359d1e1c97","MD = 9df5c16a3f580406f07d96149303d8c408869b32053b726cf3defd241e484957"], +["sha256\nLen = 184\nMsg = da999bc1f9c7acff32828a73e672d0a492f6ee895c6867","MD = 672b54e43f41ee77584bdf8bf854d97b6252c918f7ea2d26bc4097ea53a88f10"], +["sha256\nLen = 192\nMsg = 47991301156d1d977c0338efbcad41004133aefbca6bcf7e","MD = feeb4b2b59fec8fdb1e55194a493d8c871757b5723675e93d3ac034b380b7fc9"], +["sha256\nLen = 200\nMsg = 2e7ea84da4bc4d7cfb463e3f2c8647057afff3fbececa1d200","MD = 76e3acbc718836f2df8ad2d0d2d76f0cfa5fea0986be918f10bcee730df441b9"], +["sha256\nLen = 208\nMsg = 47c770eb4549b6eff6381d62e9beb464cd98d341cc1c09981a7a","MD = 6733809c73e53666c735b3bd3daf87ebc77c72756150a616a194108d71231272"], +["sha256\nLen = 216\nMsg = ac4c26d8b43b8579d8f61c9807026e83e9b586e1159bd43b851937","MD = 0e6e3c143c3a5f7f38505ed6adc9b48c18edf6dedf11635f6e8f9ac73c39fe9e"], +["sha256\nLen = 224\nMsg = 0777fc1e1ca47304c2e265692838109e26aab9e5c4ae4e8600df4b1f","MD = ffb4fc03e054f8ecbc31470fc023bedcd4a406b9dd56c71da1b660dcc4842c65"], +["sha256\nLen = 232\nMsg = 1a57251c431d4e6c2e06d65246a296915071a531425ecf255989422a66","MD = c644612cd326b38b1c6813b1daded34448805aef317c35f548dfb4a0d74b8106"], +["sha256\nLen = 240\nMsg = 9b245fdad9baeb890d9c0d0eff816efb4ca138610bc7d78cb1a801ed3273","MD = c0e29eeeb0d3a7707947e623cdc7d1899adc70dd7861205ea5e5813954fb7957"], +["sha256\nLen = 248\nMsg = 95a765809caf30ada90ad6d61c2b4b30250df0a7ce23b7753c9187f4319ce2","MD = a4139b74b102cf1e2fce229a6cd84c87501f50afa4c80feacf7d8cf5ed94f042"], +["sha256\nLen = 256\nMsg = 09fc1accc230a205e4a208e64a8f204291f581a12756392da4b8c0cf5ef02b95","MD = 4f44c1c7fbebb6f9601829f3897bfd650c56fa07844be76489076356ac1886a4"], +["sha256\nLen = 264\nMsg = 0546f7b8682b5b95fd32385faf25854cb3f7b40cc8fa229fbd52b16934aab388a7","MD = b31ad3cd02b10db282b3576c059b746fb24ca6f09fef69402dc90ece7421cbb7"], +["sha256\nLen = 272\nMsg = b12db4a1025529b3b7b1e45c6dbc7baa8897a0576e66f64bf3f8236113a6276ee77d","MD = 1c38bf6bbfd32292d67d1d651fd9d5b623b6ec1e854406223f51d0df46968712"], +["sha256\nLen = 280\nMsg = e68cb6d8c1866c0a71e7313f83dc11a5809cf5cfbeed1a587ce9c2c92e022abc1644bb","MD = c2684c0dbb85c232b6da4fb5147dd0624429ec7e657991edd95eda37a587269e"], +["sha256\nLen = 288\nMsg = 4e3d8ac36d61d9e51480831155b253b37969fe7ef49db3b39926f3a00b69a36774366000","MD = bf9d5e5b5393053f055b380baed7e792ae85ad37c0ada5fd4519542ccc461cf3"], +["sha256\nLen = 296\nMsg = 03b264be51e4b941864f9b70b4c958f5355aac294b4b87cb037f11f85f07eb57b3f0b89550","MD = d1f8bd684001ac5a4b67bbf79f87de524d2da99ac014dec3e4187728f4557471"], +["sha256\nLen = 304\nMsg = d0fefd96787c65ffa7f910d6d0ada63d64d5c4679960e7f06aeb8c70dfef954f8e39efdb629b","MD = 49ba38db85c2796f85ffd57dd5ec337007414528ae33935b102d16a6b91ba6c1"], +["sha256\nLen = 312\nMsg = b7c79d7e5f1eeccdfedf0e7bf43e730d447e607d8d1489823d09e11201a0b1258039e7bd4875b1","MD = 725e6f8d888ebaf908b7692259ab8839c3248edd22ca115bb13e025808654700"], +["sha256\nLen = 320\nMsg = 64cd363ecce05fdfda2486d011a3db95b5206a19d3054046819dd0d36783955d7e5bf8ba18bf738a","MD = 32caef024f84e97c30b4a7b9d04b678b3d8a6eb2259dff5b7f7c011f090845f8"], +["sha256\nLen = 328\nMsg = 6ac6c63d618eaf00d91c5e2807e83c093912b8e202f78e139703498a79c6067f54497c6127a23910a6","MD = 4bb33e7c6916e08a9b3ed6bcef790aaaee0dcf2e7a01afb056182dea2dad7d63"], +["sha256\nLen = 336\nMsg = d26826db9baeaa892691b68900b96163208e806a1da077429e454fa011840951a031327e605ab82ecce2","MD = 3ac7ac6bed82fdc8cd15b746f0ee7489158192c238f371c1883c9fe90b3e2831"], +["sha256\nLen = 344\nMsg = 3f7a059b65d6cb0249204aac10b9f1a4ac9e5868adebbe935a9eb5b9019e1c938bfc4e5c5378997a3947f2","MD = bfce809534eefe871273964d32f091fe756c71a7f512ef5f2300bcd57f699e74"], +["sha256\nLen = 352\nMsg = 60ffcb23d6b88e485b920af81d1083f6291d06ac8ca3a965b85914bc2add40544a027fca936bbde8f359051c","MD = 1d26f3e04f89b4eaa9dbed9231bb051eef2e8311ad26fe53d0bf0b821eaf7567"], +["sha256\nLen = 360\nMsg = 9ecd07b684bb9e0e6692e320cec4510ca79fcdb3a2212c26d90df65db33e692d073cc174840db797504e482eef","MD = 0ffeb644a49e787ccc6970fe29705a4f4c2bfcfe7d19741c158333ff6982cc9c"], +["sha256\nLen = 368\nMsg = 9d64de7161895884e7fa3d6e9eb996e7ebe511b01fe19cd4a6b3322e80aaf52bf6447ed1854e71001f4d54f8931d","MD = d048ee1524014adf9a56e60a388277de194c694cc787fc5a1b554ea9f07abfdf"], +["sha256\nLen = 376\nMsg = c4ad3c5e78d917ecb0cbbcd1c481fc2aaf232f7e289779f40e504cc309662ee96fecbd20647ef00e46199fbc482f46","MD = 50dbf40066f8d270484ee2ef6632282dfa300a85a8530eceeb0e04275e1c1efd"], +["sha256\nLen = 384\nMsg = 4eef5107459bddf8f24fc7656fd4896da8711db50400c0164847f692b886ce8d7f4d67395090b3534efd7b0d298da34b","MD = 7c5d14ed83dab875ac25ce7feed6ef837d58e79dc601fb3c1fca48d4464e8b83"], +["sha256\nLen = 392\nMsg = 047d2758e7c2c9623f9bdb93b6597c5e84a0cd34e610014bcb25b49ed05c7e356e98c7a672c3dddcaeb84317ef614d342f","MD = 7d53eccd03da37bf58c1962a8f0f708a5c5c447f6a7e9e26137c169d5bdd82e4"], +["sha256\nLen = 400\nMsg = 3d83df37172c81afd0de115139fbf4390c22e098c5af4c5ab4852406510bc0e6cf741769f44430c5270fdae0cb849d71cbab","MD = 99dc772e91ea02d9e421d552d61901016b9fd4ad2df4a8212c1ec5ba13893ab2"], +["sha256\nLen = 408\nMsg = 33fd9bc17e2b271fa04c6b93c0bdeae98654a7682d31d9b4dab7e6f32cd58f2f148a68fbe7a88c5ab1d88edccddeb30ab21e5e","MD = cefdae1a3d75e792e8698d5e71f177cc761314e9ad5df9602c6e60ae65c4c267"], +["sha256\nLen = 416\nMsg = 77a879cfa11d7fcac7a8282cc38a43dcf37643cc909837213bd6fd95d956b219a1406cbe73c52cd56c600e55b75bc37ea69641bc","MD = c99d64fa4dadd4bc8a389531c68b4590c6df0b9099c4d583bc00889fb7b98008"], +["sha256\nLen = 424\nMsg = 45a3e6b86527f20b4537f5af96cfc5ad8777a2dde6cf7511886c5590ece24fc61b226739d207dabfe32ba6efd9ff4cd5db1bd5ead3","MD = 4d12a849047c6acd4b2eee6be35fa9051b02d21d50d419543008c1d82c427072"], +["sha256\nLen = 432\nMsg = 25362a4b9d74bde6128c4fdc672305900947bc3ada9d9d316ebcf1667ad4363189937251f149c72e064a48608d940b7574b17fefc0df","MD = f8e4ccab6c979229f6066cc0cb0cfa81bb21447c16c68773be7e558e9f9d798d"], +["sha256\nLen = 440\nMsg = 3ebfb06db8c38d5ba037f1363e118550aad94606e26835a01af05078533cc25f2f39573c04b632f62f68c294ab31f2a3e2a1a0d8c2be51","MD = 6595a2ef537a69ba8583dfbf7f5bec0ab1f93ce4c8ee1916eff44a93af5749c4"], +["sha256\nLen = 448\nMsg = 2d52447d1244d2ebc28650e7b05654bad35b3a68eedc7f8515306b496d75f3e73385dd1b002625024b81a02f2fd6dffb6e6d561cb7d0bd7a","MD = cfb88d6faf2de3a69d36195acec2e255e2af2b7d933997f348e09f6ce5758360"], +["sha256\nLen = 456\nMsg = 4cace422e4a015a75492b3b3bbfbdf3758eaff4fe504b46a26c90dacc119fa9050f603d2b58b398cad6d6d9fa922a154d9e0bc4389968274b0","MD = 4d54b2d284a6794581224e08f675541c8feab6eefa3ac1cfe5da4e03e62f72e4"], +["sha256\nLen = 464\nMsg = 8620b86fbcaace4ff3c2921b8466ddd7bacae07eefef693cf17762dcabb89a84010fc9a0fb76ce1c26593ad637a61253f224d1b14a05addccabe","MD = dba490256c9720c54c612a5bd1ef573cd51dc12b3e7bd8c6db2eabe0aacb846b"], +["sha256\nLen = 472\nMsg = d1be3f13febafefc14414d9fb7f693db16dc1ae270c5b647d80da8583587c1ad8cb8cb01824324411ca5ace3ca22e179a4ff4986f3f21190f3d7f3","MD = 02804978eba6e1de65afdbc6a6091ed6b1ecee51e8bff40646a251de6678b7ef"], +["sha256\nLen = 480\nMsg = f499cc3f6e3cf7c312ffdfba61b1260c37129c1afb391047193367b7b2edeb579253e51d62ba6d911e7b818ccae1553f6146ea780f78e2219f629309","MD = 0b66c8b4fefebc8dc7da0bbedc1114f228aa63c37d5c30e91ab500f3eadfcec5"], +["sha256\nLen = 488\nMsg = 6dd6efd6f6caa63b729aa8186e308bc1bda06307c05a2c0ae5a3684e6e460811748690dc2b58775967cfcc645fd82064b1279fdca771803db9dca0ff53","MD = c464a7bf6d180de4f744bb2fe5dc27a3f681334ffd54a9814650e60260a478e3"], +["sha256\nLen = 496\nMsg = 6511a2242ddb273178e19a82c57c85cb05a6887ff2014cf1a31cb9ba5df1695aadb25c22b3c5ed51c10d047d256b8e3442842ae4e6c525f8d7a5a944af2a","MD = d6859c0b5a0b66376a24f56b2ab104286ed0078634ba19112ace0d6d60a9c1ae"], +["sha256\nLen = 504\nMsg = e2f76e97606a872e317439f1a03fcd92e632e5bd4e7cbc4e97f1afc19a16fde92d77cbe546416b51640cddb92af996534dfd81edb17c4424cf1ac4d75aceeb","MD = 18041bd4665083001fba8c5411d2d748e8abbfdcdfd9218cb02b68a78e7d4c23"], +["sha256\nLen = 512\nMsg = 5a86b737eaea8ee976a0a24da63e7ed7eefad18a101c1211e2b3650c5187c2a8a650547208251f6d4237e661c7bf4c77f335390394c37fa1a9f9be836ac28509","MD = 42e61e174fbb3897d6dd6cef3dd2802fe67b331953b06114a65c772859dfc1aa"] +]} diff --git a/app/specs/standards/debt/rfc6901.json b/app/specs/standards/debt/rfc6901.json new file mode 100644 index 00000000..5605f80c --- /dev/null +++ b/app/specs/standards/debt/rfc6901.json @@ -0,0 +1,5 @@ +[ + "rfc6901-4-a29c85e1", + "rfc6901-5-3520c6ca", + "rfc6901-7-c1ea989d" +] diff --git a/app/specs/standards/debt/rfc6902.json b/app/specs/standards/debt/rfc6902.json new file mode 100644 index 00000000..b370cf5d --- /dev/null +++ b/app/specs/standards/debt/rfc6902.json @@ -0,0 +1,15 @@ +[ + "rfc6902-4-174d230e", + "rfc6902-4-30dabaa7", + "rfc6902-4.1-ae9fcb99", + "rfc6902-4.1-dd5c908f", + "rfc6902-4.2-2b1ef42f", + "rfc6902-4.3-2b1ef42f", + "rfc6902-4.3-460c075d", + "rfc6902-4.4-8bf2ea5e", + "rfc6902-4.4-96f491da", + "rfc6902-4.4-c85200d6", + "rfc6902-4.5-2c90fd3c", + "rfc6902-4.5-c85200d6", + "rfc6902-4.6-dca29c99" +] diff --git a/app/specs/standards/debt/rfc8785.json b/app/specs/standards/debt/rfc8785.json new file mode 100644 index 00000000..8e37534c --- /dev/null +++ b/app/specs/standards/debt/rfc8785.json @@ -0,0 +1,16 @@ +[ + "rfc8785-3-4f497a80", + "rfc8785-3.1-14f3ad1b", + "rfc8785-3.1-321d353e", + "rfc8785-3.1-95a5d7cd", + "rfc8785-3.1-b5bb857d", + "rfc8785-3.1-ffeae857", + "rfc8785-3.2.2.2-2eedd5b0", + "rfc8785-3.2.2.3-2f82800e", + "rfc8785-5-a93c4d93", + "rfc8785-5-f7ceb343", + "rfc8785-B-f6a97ac2", + "rfc8785-D-c076c308", + "rfc8785-E-0ee0bc2a", + "rfc8785-E-cc549aff" +] diff --git a/app/specs/standards/register/rfc6901.json b/app/specs/standards/register/rfc6901.json new file mode 100644 index 00000000..090ffccd --- /dev/null +++ b/app/specs/standards/register/rfc6901.json @@ -0,0 +1,26 @@ +{ + "key": "rfc6901", + "title": "RFC 6901 JavaScript Object Notation (JSON) Pointer", + "issuer": "IETF", + "text": { + "url": "https://www.rfc-editor.org/rfc/rfc6901.txt", + "sha256": "12f9f4fc13d686aa4fbe7d144d70166cd3fcd4ab89174c2b13bda8f4b55e49da" + }, + "inventories": [ + { + "generated": "test/standards/generated/rfc6901.jsonl", + "vendored": "app/specs/standards/texts/12f9f4fc13d686aa4fbe7d144d70166cd3fcd4ab89174c2b13bda8f4b55e49da", + "source": { + "url": "https://www.rfc-editor.org/rfc/rfc6901.txt", + "sha256": "12f9f4fc13d686aa4fbe7d144d70166cd3fcd4ab89174c2b13bda8f4b55e49da" + } + } + ], + "governs": [ + "app/src/PrismSnapshot.lex.tex", + "site/snapshot/guest.mjs" + ], + "realizedBy": [ + "ST-01" + ] +} diff --git a/app/specs/standards/register/rfc6902.json b/app/specs/standards/register/rfc6902.json new file mode 100644 index 00000000..286aa320 --- /dev/null +++ b/app/specs/standards/register/rfc6902.json @@ -0,0 +1,48 @@ +{ + "key": "rfc6902", + "title": "RFC 6902 JavaScript Object Notation (JSON) Patch", + "issuer": "IETF", + "text": { + "url": "https://www.rfc-editor.org/rfc/rfc6902.txt", + "sha256": "ded8fa1754ab1566fd72611c9d5bcde931cd2bdf8351889e2ef5b50efdf1eed4" + }, + "inventories": [ + { + "generated": "test/standards/generated/rfc6902.jsonl", + "vendored": "app/specs/standards/texts/ded8fa1754ab1566fd72611c9d5bcde931cd2bdf8351889e2ef5b50efdf1eed4", + "source": { + "url": "https://www.rfc-editor.org/rfc/rfc6902.txt", + "sha256": "ded8fa1754ab1566fd72611c9d5bcde931cd2bdf8351889e2ef5b50efdf1eed4" + } + } + ], + "governs": [ + "app/src/PrismSnapshot.lex.tex", + "site/snapshot/guest.mjs" + ], + "realizedBy": [ + "ST-01" + ], + "enforcedBy": { + "rfc6902-4-5d946f07": { + "suite": "crates/conformance/tests/guests.rs", + "how": "json-patch-tests spec_tests.json (RFC 6902 Appendix A) case A.13, an operation with two op members, is answered by refusal; prismpm build runs every acceptance vector of the snapshot guest (app/specs/snapshot/spec.json, written from the oracles by generators/snapshot) and GU-01 holds the pinned wasm to those vectors" + }, + "rfc6902-4-d4abf196": { + "suite": "crates/conformance/tests/guests.rs", + "how": "json-patch-tests spec_tests.json (RFC 6902 Appendix A) case A.11, an add with the undefined member xyz, is answered by the document the add alone gives; prismpm build runs every acceptance vector of the snapshot guest (app/specs/snapshot/spec.json, written from the oracles by generators/snapshot) and GU-01 holds the pinned wasm to those vectors" + }, + "rfc6902-4.1-06d0e10d": { + "suite": "crates/conformance/tests/guests.rs", + "how": "json-patch-tests spec_tests.json (RFC 6902 Appendix A) case A.12 and the 4.1 missing-object case, adds whose target's parent does not exist, are answered by refusal; A.1, A.2, A.10 and A.16 by the added documents; prismpm build runs every acceptance vector of the snapshot guest (app/specs/snapshot/spec.json, written from the oracles by generators/snapshot) and GU-01 holds the pinned wasm to those vectors" + }, + "rfc6902-4.6-159a78dd": { + "suite": "crates/conformance/tests/guests.rs", + "how": "json-patch-tests spec_tests.json (RFC 6902 Appendix A) case A.8 is answered by the unchanged document, A.9 (a different string) and A.15 (number against string) by refusal; prismpm build runs every acceptance vector of the snapshot guest (app/specs/snapshot/spec.json, written from the oracles by generators/snapshot) and GU-01 holds the pinned wasm to those vectors" + }, + "rfc6902-5-ec058a4b": { + "suite": "crates/conformance/tests/guests.rs", + "how": "json-patch-tests spec_tests.json (RFC 6902 Appendix A) case A.9, A.12, A.13, A.15 and 4.1, patches with an operation that fails or a document that violates the RFC, are answered by refusal of the whole patch, not a partial document; prismpm build runs every acceptance vector of the snapshot guest (app/specs/snapshot/spec.json, written from the oracles by generators/snapshot) and GU-01 holds the pinned wasm to those vectors" + } + } +} diff --git a/app/specs/standards/register/rfc8785.json b/app/specs/standards/register/rfc8785.json index a98ea452..69b5bb1d 100644 --- a/app/specs/standards/register/rfc8785.json +++ b/app/specs/standards/register/rfc8785.json @@ -2,10 +2,79 @@ "key": "rfc8785", "title": "RFC 8785 JSON Canonicalization Scheme", "issuer": "IETF", - "text": null, - "unpinned": "pinning with the bcp14 extractor and its test vectors", - "governs": [], + "text": { + "url": "https://www.rfc-editor.org/rfc/rfc8785.txt", + "sha256": "63d52294eb0e3f0014174288186d388b4ddbf2c67d1ce8af1d9726eb0c3ab240" + }, + "inventories": [ + { + "generated": "test/standards/generated/rfc8785.jsonl", + "vendored": "app/specs/standards/texts/63d52294eb0e3f0014174288186d388b4ddbf2c67d1ce8af1d9726eb0c3ab240", + "source": { + "url": "https://www.rfc-editor.org/rfc/rfc8785.txt", + "sha256": "63d52294eb0e3f0014174288186d388b4ddbf2c67d1ce8af1d9726eb0c3ab240" + } + } + ], + "governs": [ + "app/src/PrismSnapshot.lex.tex", + "site/snapshot/guest.mjs" + ], "realizedBy": [ "ST-01" - ] + ], + "enforcedBy": { + "rfc8785-3.1-19737ffb": { + "suite": "crates/conformance/tests/guests.rs", + "how": "the RFC 8785 author's test data (cyberphone/json-canonicalization) unicode.json: the unnormalized A\\u030a is serialized as those two code points, not normalized; prismpm build runs every acceptance vector of the snapshot guest (app/specs/snapshot/spec.json, written from the oracles by generators/snapshot) and GU-01 holds the pinned wasm to those vectors" + }, + "rfc8785-3.1-89b727e4": { + "suite": "crates/conformance/tests/guests.rs", + "how": "the RFC 8785 author's test data (cyberphone/json-canonicalization) unicode.json: the unnormalized A\\u030a is serialized as those two code points, not normalized; prismpm build runs every acceptance vector of the snapshot guest (app/specs/snapshot/spec.json, written from the oracles by generators/snapshot) and GU-01 holds the pinned wasm to those vectors" + }, + "rfc8785-3.2.1-f7828dcb": { + "suite": "crates/conformance/tests/guests.rs", + "how": "the RFC 8785 author's test data (cyberphone/json-canonicalization) every input, whitespace between tokens included, is answered by its output byte for byte, which has none; prismpm build runs every acceptance vector of the snapshot guest (app/specs/snapshot/spec.json, written from the oracles by generators/snapshot) and GU-01 holds the pinned wasm to those vectors" + }, + "rfc8785-3.2.2.1-d73f46ac": { + "suite": "crates/conformance/tests/guests.rs", + "how": "the RFC 8785 author's test data (cyberphone/json-canonicalization) values.json: [null, true, false] is answered as [null,true,false]; prismpm build runs every acceptance vector of the snapshot guest (app/specs/snapshot/spec.json, written from the oracles by generators/snapshot) and GU-01 holds the pinned wasm to those vectors" + }, + "rfc8785-3.2.2.2-4e479461": { + "suite": "crates/conformance/tests/guests.rs", + "how": "the RFC 8785 author's test data (cyberphone/json-canonicalization) values.json and weird.json: non-control code points are written as is, and \\\\ and \\\" as escapes; prismpm build runs every acceptance vector of the snapshot guest (app/specs/snapshot/spec.json, written from the oracles by generators/snapshot) and GU-01 holds the pinned wasm to those vectors" + }, + "rfc8785-3.2.2.2-5658b4ab": { + "suite": "crates/conformance/tests/guests.rs", + "how": "the RFC 8785 author's test data (cyberphone/json-canonicalization) values.json: U+000F is written \\u000f and U+000A as \\n; prismpm build runs every acceptance vector of the snapshot guest (app/specs/snapshot/spec.json, written from the oracles by generators/snapshot) and GU-01 holds the pinned wasm to those vectors" + }, + "rfc8785-3.2.2.2-7e32fd81": { + "suite": "crates/conformance/tests/guests.rs", + "how": "the RFC 8785 author's test data (cyberphone/json-canonicalization) values.json, weird.json, french.json: every string and property name is answered byte for byte as the output serializes it; prismpm build runs every acceptance vector of the snapshot guest (app/specs/snapshot/spec.json, written from the oracles by generators/snapshot) and GU-01 holds the pinned wasm to those vectors" + }, + "rfc8785-3.2.2.2-bdf9de0e": { + "suite": "crates/conformance/tests/guests.rs", + "how": "the RFC 8785 author's test data (cyberphone/json-canonicalization) every string of every output is enclosed in double quotes, byte for byte; prismpm build runs every acceptance vector of the snapshot guest (app/specs/snapshot/spec.json, written from the oracles by generators/snapshot) and GU-01 holds the pinned wasm to those vectors" + }, + "rfc8785-3.2.2.3-44488107": { + "suite": "crates/conformance/tests/guests.rs", + "how": "the RFC 8785 author's test data (cyberphone/json-canonicalization) values.json: 333333333.33333329, 1E30, 4.50, 2e-3 and 1e-27 are answered as ECMAScript serializes them; prismpm build runs every acceptance vector of the snapshot guest (app/specs/snapshot/spec.json, written from the oracles by generators/snapshot) and GU-01 holds the pinned wasm to those vectors" + }, + "rfc8785-3.2.3-0281d99a": { + "suite": "crates/conformance/tests/guests.rs", + "how": "the RFC 8785 author's test data (cyberphone/json-canonicalization) weird.json and french.json: properties are sorted by UTF-16 code units, the surrogate pair of U+1F602 before U+FB33, not by locale; prismpm build runs every acceptance vector of the snapshot guest (app/specs/snapshot/spec.json, written from the oracles by generators/snapshot) and GU-01 holds the pinned wasm to those vectors" + }, + "rfc8785-3.2.3-36b63a1b": { + "suite": "crates/conformance/tests/guests.rs", + "how": "the RFC 8785 author's test data (cyberphone/json-canonicalization) arrays.json: the object inside the array has its properties sorted and the array keeps its order; prismpm build runs every acceptance vector of the snapshot guest (app/specs/snapshot/spec.json, written from the oracles by generators/snapshot) and GU-01 holds the pinned wasm to those vectors" + }, + "rfc8785-3.2.3-8ee23ccb": { + "suite": "crates/conformance/tests/guests.rs", + "how": "the RFC 8785 author's test data (cyberphone/json-canonicalization) structures.json: child objects have their properties sorted at every depth; prismpm build runs every acceptance vector of the snapshot guest (app/specs/snapshot/spec.json, written from the oracles by generators/snapshot) and GU-01 holds the pinned wasm to those vectors" + }, + "rfc8785-3.2.4-42882237": { + "suite": "crates/conformance/tests/guests.rs", + "how": "the RFC 8785 author's test data (cyberphone/json-canonicalization) weird.json, french.json and values.json: the answer is the UTF-8 bytes of the output file; prismpm build runs every acceptance vector of the snapshot guest (app/specs/snapshot/spec.json, written from the oracles by generators/snapshot) and GU-01 holds the pinned wasm to those vectors" + } + } } diff --git a/app/specs/standards/texts/12f9f4fc13d686aa4fbe7d144d70166cd3fcd4ab89174c2b13bda8f4b55e49da b/app/specs/standards/texts/12f9f4fc13d686aa4fbe7d144d70166cd3fcd4ab89174c2b13bda8f4b55e49da new file mode 100644 index 00000000..5d842de8 --- /dev/null +++ b/app/specs/standards/texts/12f9f4fc13d686aa4fbe7d144d70166cd3fcd4ab89174c2b13bda8f4b55e49da @@ -0,0 +1,451 @@ + + + + + + +Internet Engineering Task Force (IETF) P. Bryan, Ed. +Request for Comments: 6901 Salesforce.com +Category: Standards Track K. Zyp +ISSN: 2070-1721 SitePen (USA) + M. Nottingham, Ed. + Akamai + April 2013 + + + JavaScript Object Notation (JSON) Pointer + +Abstract + + JSON Pointer defines a string syntax for identifying a specific value + within a JavaScript Object Notation (JSON) document. + +Status of This Memo + + This is an Internet Standards Track document. + + This document is a product of the Internet Engineering Task Force + (IETF). It represents the consensus of the IETF community. It has + received public review and has been approved for publication by the + Internet Engineering Steering Group (IESG). Further information on + Internet Standards is available in Section 2 of RFC 5741. + + Information about the current status of this document, any errata, + and how to provide feedback on it may be obtained at + http://www.rfc-editor.org/info/rfc6901. + +Copyright Notice + + Copyright (c) 2013 IETF Trust and the persons identified as the + document authors. All rights reserved. + + This document is subject to BCP 78 and the IETF Trust's Legal + Provisions Relating to IETF Documents + (http://trustee.ietf.org/license-info) in effect on the date of + publication of this document. Please review these documents + carefully, as they describe your rights and restrictions with respect + to this document. Code Components extracted from this document must + include Simplified BSD License text as described in Section 4.e of + the Trust Legal Provisions and are provided without warranty as + described in the Simplified BSD License. + + + + + + + +Bryan, et al. Standards Track [Page 1] + +RFC 6901 JSON Pointer April 2013 + + +Table of Contents + + 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 2 + 2. Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . 2 + 3. Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 + 4. Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . 3 + 5. JSON String Representation . . . . . . . . . . . . . . . . . . 4 + 6. URI Fragment Identifier Representation . . . . . . . . . . . . 5 + 7. Error Handling . . . . . . . . . . . . . . . . . . . . . . . . 6 + 8. Security Considerations . . . . . . . . . . . . . . . . . . . . 6 + 9. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . 7 + 10. References . . . . . . . . . . . . . . . . . . . . . . . . . . 7 + 10.1. Normative References . . . . . . . . . . . . . . . . . . . 7 + 10.2. Informative References . . . . . . . . . . . . . . . . . . 7 + +1. Introduction + + This specification defines JSON Pointer, a string syntax for + identifying a specific value within a JavaScript Object Notation + (JSON) document [RFC4627]. JSON Pointer is intended to be easily + expressed in JSON string values as well as Uniform Resource + Identifier (URI) [RFC3986] fragment identifiers. + +2. Conventions + + The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", + "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this + document are to be interpreted as described in [RFC2119]. + + This specification expresses normative syntax rules using Augmented + Backus-Naur Form (ABNF) [RFC5234] notation. + +3. Syntax + + A JSON Pointer is a Unicode string (see [RFC4627], Section 3) + containing a sequence of zero or more reference tokens, each prefixed + by a '/' (%x2F) character. + + Because the characters '~' (%x7E) and '/' (%x2F) have special + meanings in JSON Pointer, '~' needs to be encoded as '~0' and '/' + needs to be encoded as '~1' when these characters appear in a + reference token. + + + + + + + + + +Bryan, et al. Standards Track [Page 2] + +RFC 6901 JSON Pointer April 2013 + + + The ABNF syntax of a JSON Pointer is: + + json-pointer = *( "/" reference-token ) + reference-token = *( unescaped / escaped ) + unescaped = %x00-2E / %x30-7D / %x7F-10FFFF + ; %x2F ('/') and %x7E ('~') are excluded from 'unescaped' + escaped = "~" ( "0" / "1" ) + ; representing '~' and '/', respectively + + It is an error condition if a JSON Pointer value does not conform to + this syntax (see Section 7). + + Note that JSON Pointers are specified in characters, not as bytes. + +4. Evaluation + + Evaluation of a JSON Pointer begins with a reference to the root + value of a JSON document and completes with a reference to some value + within the document. Each reference token in the JSON Pointer is + evaluated sequentially. + + Evaluation of each reference token begins by decoding any escaped + character sequence. This is performed by first transforming any + occurrence of the sequence '~1' to '/', and then transforming any + occurrence of the sequence '~0' to '~'. By performing the + substitutions in this order, an implementation avoids the error of + turning '~01' first into '~1' and then into '/', which would be + incorrect (the string '~01' correctly becomes '~1' after + transformation). + + The reference token then modifies which value is referenced according + to the following scheme: + + o If the currently referenced value is a JSON object, the new + referenced value is the object member with the name identified by + the reference token. The member name is equal to the token if it + has the same number of Unicode characters as the token and their + code points are byte-by-byte equal. No Unicode character + normalization is performed. If a referenced member name is not + unique in an object, the member that is referenced is undefined, + and evaluation fails (see below). + + + + + + + + + + +Bryan, et al. Standards Track [Page 3] + +RFC 6901 JSON Pointer April 2013 + + + o If the currently referenced value is a JSON array, the reference + token MUST contain either: + + * characters comprised of digits (see ABNF below; note that + leading zeros are not allowed) that represent an unsigned + base-10 integer value, making the new referenced value the + array element with the zero-based index identified by the + token, or + + * exactly the single character "-", making the new referenced + value the (nonexistent) member after the last array element. + + The ABNF syntax for array indices is: + + array-index = %x30 / ( %x31-39 *(%x30-39) ) + ; "0", or digits without a leading "0" + + Implementations will evaluate each reference token against the + document's contents and will raise an error condition if it fails to + resolve a concrete value for any of the JSON pointer's reference + tokens. For example, if an array is referenced with a non-numeric + token, an error condition will be raised. See Section 7 for details. + + Note that the use of the "-" character to index an array will always + result in such an error condition because by definition it refers to + a nonexistent array element. Thus, applications of JSON Pointer need + to specify how that character is to be handled, if it is to be + useful. + + Any error condition for which a specific action is not defined by the + JSON Pointer application results in termination of evaluation. + +5. JSON String Representation + + A JSON Pointer can be represented in a JSON string value. Per + [RFC4627], Section 2.5, all instances of quotation mark '"' (%x22), + reverse solidus '\' (%x5C), and control (%x00-1F) characters MUST be + escaped. + + Note that before processing a JSON string as a JSON Pointer, + backslash escape sequences must be unescaped. + + + + + + + + + + +Bryan, et al. Standards Track [Page 4] + +RFC 6901 JSON Pointer April 2013 + + + For example, given the JSON document + + { + "foo": ["bar", "baz"], + "": 0, + "a/b": 1, + "c%d": 2, + "e^f": 3, + "g|h": 4, + "i\\j": 5, + "k\"l": 6, + " ": 7, + "m~n": 8 + } + + The following JSON strings evaluate to the accompanying values: + + "" // the whole document + "/foo" ["bar", "baz"] + "/foo/0" "bar" + "/" 0 + "/a~1b" 1 + "/c%d" 2 + "/e^f" 3 + "/g|h" 4 + "/i\\j" 5 + "/k\"l" 6 + "/ " 7 + "/m~0n" 8 + +6. URI Fragment Identifier Representation + + A JSON Pointer can be represented in a URI fragment identifier by + encoding it into octets using UTF-8 [RFC3629], while percent-encoding + those characters not allowed by the fragment rule in [RFC3986]. + + Note that a given media type needs to specify JSON Pointer as its + fragment identifier syntax explicitly (usually, in its registration + [RFC6838]). That is, just because a document is JSON does not imply + that JSON Pointer can be used as its fragment identifier syntax. In + particular, the fragment identifier syntax for application/json is + not JSON Pointer. + + + + + + + + + +Bryan, et al. Standards Track [Page 5] + +RFC 6901 JSON Pointer April 2013 + + + Given the same example document as above, the following URI fragment + identifiers evaluate to the accompanying values: + + # // the whole document + #/foo ["bar", "baz"] + #/foo/0 "bar" + #/ 0 + #/a~1b 1 + #/c%25d 2 + #/e%5Ef 3 + #/g%7Ch 4 + #/i%5Cj 5 + #/k%22l 6 + #/%20 7 + #/m~0n 8 + +7. Error Handling + + In the event of an error condition, evaluation of the JSON Pointer + fails to complete. + + Error conditions include, but are not limited to: + + o Invalid pointer syntax + + o A pointer that references a nonexistent value + + This specification does not define how errors are handled. An + application of JSON Pointer SHOULD specify the impact and handling of + each type of error. + + For example, some applications might stop pointer processing upon an + error, while others may attempt to recover from missing values by + inserting default ones. + +8. Security Considerations + + A given JSON Pointer is not guaranteed to reference an actual JSON + value. Therefore, applications using JSON Pointer should anticipate + this situation by defining how a pointer that does not resolve ought + to be handled. + + Note that JSON pointers can contain the NUL (Unicode U+0000) + character. Care is needed not to misinterpret this character in + programming languages that use NUL to mark the end of a string. + + + + + + +Bryan, et al. Standards Track [Page 6] + +RFC 6901 JSON Pointer April 2013 + + +9. Acknowledgements + + The following individuals contributed ideas, feedback, and wording to + this specification: + + Mike Acar, Carsten Bormann, Tim Bray, Jacob Davies, Martin J. + Duerst, Bjoern Hoehrmann, James H. Manger, Drew Perttula, and + Julian Reschke. + +10. References + +10.1. Normative References + + [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate + Requirement Levels", BCP 14, RFC 2119, March 1997. + + [RFC3629] Yergeau, F., "UTF-8, a transformation format of ISO + 10646", STD 63, RFC 3629, November 2003. + + [RFC3986] Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform + Resource Identifier (URI): Generic Syntax", STD 66, + RFC 3986, January 2005. + + [RFC4627] Crockford, D., "The application/json Media Type for + JavaScript Object Notation (JSON)", RFC 4627, July 2006. + + [RFC5234] Crocker, D. and P. Overell, "Augmented BNF for Syntax + Specifications: ABNF", STD 68, RFC 5234, January 2008. + +10.2. Informative References + + [RFC6838] Freed, N., Klensin, J., and T. Hansen, "Media Type + Specifications and Registration Procedures", BCP 13, + RFC 6838, January 2013. + + + + + + + + + + + + + + + + + +Bryan, et al. Standards Track [Page 7] + +RFC 6901 JSON Pointer April 2013 + + +Authors' Addresses + + Paul C. Bryan (editor) + Salesforce.com + + Phone: +1 604 783 1481 + EMail: pbryan@anode.ca + + + Kris Zyp + SitePen (USA) + + Phone: +1 650 968 8787 + EMail: kris@sitepen.com + + + Mark Nottingham (editor) + Akamai + + EMail: mnot@mnot.net + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Bryan, et al. Standards Track [Page 8] + diff --git a/app/specs/standards/texts/63d52294eb0e3f0014174288186d388b4ddbf2c67d1ce8af1d9726eb0c3ab240 b/app/specs/standards/texts/63d52294eb0e3f0014174288186d388b4ddbf2c67d1ce8af1d9726eb0c3ab240 new file mode 100644 index 00000000..609c4162 --- /dev/null +++ b/app/specs/standards/texts/63d52294eb0e3f0014174288186d388b4ddbf2c67d1ce8af1d9726eb0c3ab240 @@ -0,0 +1,984 @@ + + + + +Independent Submission A. Rundgren +Request for Comments: 8785 Independent +Category: Informational B. Jordan +ISSN: 2070-1721 Broadcom + S. Erdtman + Spotify AB + June 2020 + + + JSON Canonicalization Scheme (JCS) + +Abstract + + Cryptographic operations like hashing and signing need the data to be + expressed in an invariant format so that the operations are reliably + repeatable. One way to address this is to create a canonical + representation of the data. Canonicalization also permits data to be + exchanged in its original form on the "wire" while cryptographic + operations performed on the canonicalized counterpart of the data in + the producer and consumer endpoints generate consistent results. + + This document describes the JSON Canonicalization Scheme (JCS). This + specification defines how to create a canonical representation of + JSON data by building on the strict serialization methods for JSON + primitives defined by ECMAScript, constraining JSON data to the + Internet JSON (I-JSON) subset, and by using deterministic property + sorting. + +Status of This Memo + + This document is not an Internet Standards Track specification; it is + published for informational purposes. + + This is a contribution to the RFC Series, independently of any other + RFC stream. The RFC Editor has chosen to publish this document at + its discretion and makes no statement about its value for + implementation or deployment. Documents approved for publication by + the RFC Editor are not candidates for any level of Internet Standard; + see Section 2 of RFC 7841. + + Information about the current status of this document, any errata, + and how to provide feedback on it may be obtained at + https://www.rfc-editor.org/info/rfc8785. + +Copyright Notice + + Copyright (c) 2020 IETF Trust and the persons identified as the + document authors. All rights reserved. + + This document is subject to BCP 78 and the IETF Trust's Legal + Provisions Relating to IETF Documents + (https://trustee.ietf.org/license-info) in effect on the date of + publication of this document. Please review these documents + carefully, as they describe your rights and restrictions with respect + to this document. + +Table of Contents + + 1. Introduction + 2. Terminology + 3. Detailed Operation + 3.1. Creation of Input Data + 3.2. Generation of Canonical JSON Data + 3.2.1. Whitespace + 3.2.2. Serialization of Primitive Data Types + 3.2.2.1. Serialization of Literals + 3.2.2.2. Serialization of Strings + 3.2.2.3. Serialization of Numbers + 3.2.3. Sorting of Object Properties + 3.2.4. UTF-8 Generation + 4. IANA Considerations + 5. Security Considerations + 6. References + 6.1. Normative References + 6.2. Informative References + Appendix A. ECMAScript Sample Canonicalizer + Appendix B. Number Serialization Samples + Appendix C. Canonicalized JSON as "Wire Format" + Appendix D. Dealing with Big Numbers + Appendix E. String Subtype Handling + E.1. Subtypes in Arrays + Appendix F. Implementation Guidelines + Appendix G. Open-Source Implementations + Appendix H. Other JSON Canonicalization Efforts + Appendix I. Development Portal + Acknowledgements + Authors' Addresses + +1. Introduction + + This document describes the JSON Canonicalization Scheme (JCS). This + specification defines how to create a canonical representation of + JSON [RFC8259] data by building on the strict serialization methods + for JSON primitives defined by ECMAScript [ECMA-262], constraining + JSON data to the I-JSON [RFC7493] subset, and by using deterministic + property sorting. The output from JCS is a "hashable" representation + of JSON data that can be used by cryptographic methods. The + subsequent paragraphs outline the primary design considerations. + + Cryptographic operations like hashing and signing need the data to be + expressed in an invariant format so that the operations are reliably + repeatable. One way to accomplish this is to convert the data into a + format that has a simple and fixed representation, like base64url + [RFC4648]. This is how JSON Web Signature (JWS) [RFC7515] addressed + this issue. Another solution is to create a canonical version of the + data, similar to what was done for the XML signature [XMLDSIG] + standard. + + The primary advantage with a canonicalizing scheme is that data can + be kept in its original form. This is the core rationale behind JCS. + Put another way, using canonicalization enables a JSON object to + remain a JSON object even after being signed. This can simplify + system design, documentation, and logging. + + To avoid "reinventing the wheel", JCS relies on the serialization of + JSON primitives (strings, numbers, and literals), as defined by + ECMAScript (aka JavaScript) [ECMA-262] beginning with version 6. + + Seasoned XML developers may recall difficulties getting XML + signatures to validate. This was usually due to different + interpretations of the quite intricate XML canonicalization rules as + well as of the equally complex Web Services security standards. The + reasons why JCS should not suffer from similar issues are: + + * JSON does not have a namespace concept and default values. + + * Data is constrained to the I-JSON [RFC7493] subset. This + eliminates the need for specific parsers for dealing with + canonicalization. + + * JCS-compatible serialization of JSON primitives is currently + supported by most web browsers as well as by Node.js [NODEJS]. + + * The full JCS specification is currently supported by multiple + open-source implementations (see Appendix G). See also Appendix F + for implementation guidelines. + + JCS is compatible with some existing systems relying on JSON + canonicalization such as JSON Web Key (JWK) Thumbprint [RFC7638] and + Keybase [KEYBASE]. + + For potential uses outside of cryptography, see [JSONCOMP]. + + The intended audiences of this document are JSON tool vendors as well + as designers of JSON-based cryptographic solutions. The reader is + assumed to be knowledgeable in ECMAScript, including the "JSON" + object. + +2. Terminology + + Note that this document is not on the IETF standards track. However, + a conformant implementation is supposed to adhere to the specified + behavior for security and interoperability reasons. This text uses + BCP 14 to describe that necessary behavior. + + The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", + "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and + "OPTIONAL" in this document are to be interpreted as described in + BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all + capitals, as shown here. + +3. Detailed Operation + + This section describes the details related to creating a canonical + JSON representation and how they are addressed by JCS. + + Appendix F describes the RECOMMENDED way of adding JCS support to + existing JSON tools. + +3.1. Creation of Input Data + + Data to be canonically serialized is usually created by: + + * Parsing previously generated JSON data. + + * Programmatically creating data. + + Irrespective of the method used, the data to be serialized MUST be + adapted for I-JSON [RFC7493] formatting, which implies the following: + + * JSON objects MUST NOT exhibit duplicate property names. + + * JSON string data MUST be expressible as Unicode [UNICODE]. + + * JSON number data MUST be expressible as IEEE 754 [IEEE754] double- + precision values. For applications needing higher precision or + longer integers than offered by IEEE 754 double precision, it is + RECOMMENDED to represent such numbers as JSON strings; see + Appendix D for details on how this can be performed in an + interoperable and extensible way. + + An additional constraint is that parsed JSON string data MUST NOT be + altered during subsequent serializations. For more information, see + Appendix E. + + Note: Although the Unicode standard offers the possibility of + rearranging certain character sequences, referred to as "Unicode + Normalization" [UCNORM], JCS-compliant string processing does not + take this into consideration. That is, all components involved in a + scheme depending on JCS MUST preserve Unicode string data "as is". + +3.2. Generation of Canonical JSON Data + + The following subsections describe the steps required to create a + canonical JSON representation of the data elaborated on in the + previous section. + + Appendix A shows sample code for an ECMAScript-based canonicalizer, + matching the JCS specification. + +3.2.1. Whitespace + + Whitespace between JSON tokens MUST NOT be emitted. + +3.2.2. Serialization of Primitive Data Types + + Assume the following JSON object is parsed: + + { + "numbers": [333333333.33333329, 1E30, 4.50, + 2e-3, 0.000000000000000000000000001], + "string": "\u20ac$\u000F\u000aA'\u0042\u0022\u005c\\\"\/", + "literals": [null, true, false] + } + + If the parsed data is subsequently serialized using a serializer + compliant with ECMAScript's "JSON.stringify()", the result would + (with a line wrap added for display purposes only) be rather + divergent with respect to the original data: + + {"numbers":[333333333.3333333,1e+30,4.5,0.002,1e-27],"string": + "€$\u000f\nA'B\"\\\\\"/","literals":[null,true,false]} + + The reason for the difference between the parsed data and its + serialized counterpart is due to a wide tolerance on input data (as + defined by JSON [RFC8259]), while output data (as defined by + ECMAScript) has a fixed representation. As can be seen in the + example, numbers are subject to rounding as well. + + The following subsections describe the serialization of primitive + JSON data types according to JCS. This part is identical to that of + ECMAScript. In the (unlikely) event that a future version of + ECMAScript would invalidate any of the following serialization + methods, it will be up to the developer community to either stick to + this specification or create a new specification. + +3.2.2.1. Serialization of Literals + + In accordance with JSON [RFC8259], the literals "null", "true", and + "false" MUST be serialized as null, true, and false, respectively. + +3.2.2.2. Serialization of Strings + + For JSON string data (which includes JSON object property names as + well), each Unicode code point MUST be serialized as described below + (see Section 24.3.2.2 of [ECMA-262]): + + * If the Unicode value falls within the traditional ASCII control + character range (U+0000 through U+001F), it MUST be serialized + using lowercase hexadecimal Unicode notation (\uhhhh) unless it is + in the set of predefined JSON control characters U+0008, U+0009, + U+000A, U+000C, or U+000D, which MUST be serialized as \b, \t, \n, + \f, and \r, respectively. + + * If the Unicode value is outside of the ASCII control character + range, it MUST be serialized "as is" unless it is equivalent to + U+005C (\) or U+0022 ("), which MUST be serialized as \\ and \", + respectively. + + Finally, the resulting sequence of Unicode code points MUST be + enclosed in double quotes ("). + + Note: Since invalid Unicode data like "lone surrogates" (e.g., + U+DEAD) may lead to interoperability issues including broken + signatures, occurrences of such data MUST cause a compliant JCS + implementation to terminate with an appropriate error. + +3.2.2.3. Serialization of Numbers + + ECMAScript builds on the IEEE 754 [IEEE754] double-precision standard + for representing JSON number data. Such data MUST be serialized + according to Section 7.1.12.1 of [ECMA-262], including the "Note 2" + enhancement. + + Due to the relative complexity of this part, the algorithm itself is + not included in this document. For implementers of JCS-compliant + number serialization, Google's implementation in V8 [V8] may serve as + a reference. Another compatible number serialization reference + implementation is Ryu [RYU], which is used by the JCS open-source + Java implementation mentioned in Appendix G. Appendix B holds a set + of IEEE 754 sample values and their corresponding JSON serialization. + + Note: Since Not a Number (NaN) and Infinity are not permitted in + JSON, occurrences of NaN or Infinity MUST cause a compliant JCS + implementation to terminate with an appropriate error. + +3.2.3. Sorting of Object Properties + + Although the previous step normalized the representation of primitive + JSON data types, the result would not yet qualify as "canonical" + since JSON object properties are not in lexicographic (alphabetical) + order. + + Applied to the sample in Section 3.2.2, a properly canonicalized + version should (with a line wrap added for display purposes only) + read as: + + {"literals":[null,true,false],"numbers":[333333333.3333333, + 1e+30,4.5,0.002,1e-27],"string":"€$\u000f\nA'B\"\\\\\"/"} + + The rules for lexicographic sorting of JSON object properties + according to JCS are as follows: + + * JSON object properties MUST be sorted recursively, which means + that JSON child Objects MUST have their properties sorted as well. + + * JSON array data MUST also be scanned for the presence of JSON + objects (if an object is found, then its properties MUST be + sorted), but array element order MUST NOT be changed. + + When a JSON object is about to have its properties sorted, the + following measures MUST be adhered to: + + * The sorting process is applied to property name strings in their + "raw" (unescaped) form. That is, a newline character is treated + as U+000A. + + * Property name strings to be sorted are formatted as arrays of + UTF-16 [UNICODE] code units. The sorting is based on pure value + comparisons, where code units are treated as unsigned integers, + independent of locale settings. + + * Property name strings either have different values at some index + that is a valid index for both strings, or their lengths are + different, or both. If they have different values at one or more + index positions, let k be the smallest such index; then, the + string whose value at position k has the smaller value, as + determined by using the "<" operator, lexicographically precedes + the other string. If there is no index position at which they + differ, then the shorter string lexicographically precedes the + longer string. + + In plain English, this means that property names are sorted in + ascending order like the following: + + "" + "a" + "aa" + "ab" + + The rationale for basing the sorting algorithm on UTF-16 code units + is that it maps directly to the string type in ECMAScript (featured + in web browsers and Node.js), Java, and .NET. In addition, JSON only + supports escape sequences expressed as UTF-16 code units, making + knowledge and handling of such data a necessity anyway. Systems + using another internal representation of string data will need to + convert JSON property name strings into arrays of UTF-16 code units + before sorting. The conversion from UTF-8 or UTF-32 to UTF-16 is + defined by the Unicode [UNICODE] standard. + + The following JSON test data can be used for verifying the + correctness of the sorting scheme in a JCS implementation: + + { + "\u20ac": "Euro Sign", + "\r": "Carriage Return", + "\ufb33": "Hebrew Letter Dalet With Dagesh", + "1": "One", + "\ud83d\ude00": "Emoji: Grinning Face", + "\u0080": "Control", + "\u00f6": "Latin Small Letter O With Diaeresis" + } + + Expected argument order after sorting property strings: + + "Carriage Return" + "One" + "Control" + "Latin Small Letter O With Diaeresis" + "Euro Sign" + "Emoji: Grinning Face" + "Hebrew Letter Dalet With Dagesh" + + Note: For the purpose of obtaining a deterministic property order, + sorting of data encoded in UTF-8 or UTF-32 would also work, but the + outcome for JSON data like above would differ and thus be + incompatible with this specification. However, in practice, property + names are rarely defined outside of 7-bit ASCII, making it possible + to sort string data in UTF-8 or UTF-32 format without conversion to + UTF-16 and still be compatible with JCS. Whether or not this is a + viable option depends on the environment JCS is used in. + +3.2.4. UTF-8 Generation + + Finally, in order to create a platform-independent representation, + the result of the preceding step MUST be encoded in UTF-8. + + Applied to the sample in Section 3.2.3, this should yield the + following bytes, here shown in hexadecimal notation: + + 7b 22 6c 69 74 65 72 61 6c 73 22 3a 5b 6e 75 6c 6c 2c 74 72 + 75 65 2c 66 61 6c 73 65 5d 2c 22 6e 75 6d 62 65 72 73 22 3a + 5b 33 33 33 33 33 33 33 33 33 2e 33 33 33 33 33 33 33 2c 31 + 65 2b 33 30 2c 34 2e 35 2c 30 2e 30 30 32 2c 31 65 2d 32 37 + 5d 2c 22 73 74 72 69 6e 67 22 3a 22 e2 82 ac 24 5c 75 30 30 + 30 66 5c 6e 41 27 42 5c 22 5c 5c 5c 5c 5c 22 2f 22 7d + + This data is intended to be usable as input to cryptographic methods. + +4. IANA Considerations + + This document has no IANA actions. + +5. Security Considerations + + It is crucial to perform sanity checks on input data to avoid + overflowing buffers and similar things that could affect the + integrity of the system. + + When JCS is applied to signature schemes like the one described in + Appendix F, applications MUST perform the following operations before + acting upon received data: + + 1. Parse the JSON data and verify that it adheres to I-JSON. + + 2. Verify the data for correctness according to the conventions + defined by the ecosystem where it is to be used. This also + includes locating the property holding the signature data. + + 3. Verify the signature. + + If any of these steps fail, the operation in progress MUST be + aborted. + +6. References + +6.1. Normative References + + [ECMA-262] ECMA International, "ECMAScript 2019 Language + Specification", Standard ECMA-262 10th Edition, June 2019, + . + + [IEEE754] IEEE, "IEEE Standard for Floating-Point Arithmetic", IEEE + 754-2019, DOI 10.1109/IEEESTD.2019.8766229, + . + + [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate + Requirement Levels", BCP 14, RFC 2119, + DOI 10.17487/RFC2119, March 1997, + . + + [RFC7493] Bray, T., Ed., "The I-JSON Message Format", RFC 7493, + DOI 10.17487/RFC7493, March 2015, + . + + [RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC + 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, + May 2017, . + + [RFC8259] Bray, T., Ed., "The JavaScript Object Notation (JSON) Data + Interchange Format", STD 90, RFC 8259, + DOI 10.17487/RFC8259, December 2017, + . + + [UCNORM] The Unicode Consortium, "Unicode Normalization Forms", + . + + [UNICODE] The Unicode Consortium, "The Unicode Standard", + . + +6.2. Informative References + + [JSONCOMP] Rundgren, A., ""Comparable" JSON (JSONCOMP)", Work in + Progress, Internet-Draft, draft-rundgren-comparable-json- + 04, 13 February 2019, . + + [KEYBASE] Keybase, "Canonical Packings for JSON and Msgpack", + . + + [NODEJS] OpenJS Foundation, "Node.js", . + + [OPENAPI] OpenAPI Initiative, "The OpenAPI Specification: a broadly + adopted industry standard for describing modern APIs", + . + + [RFC4648] Josefsson, S., "The Base16, Base32, and Base64 Data + Encodings", RFC 4648, DOI 10.17487/RFC4648, October 2006, + . + + [RFC7515] Jones, M., Bradley, J., and N. Sakimura, "JSON Web + Signature (JWS)", RFC 7515, DOI 10.17487/RFC7515, May + 2015, . + + [RFC7638] Jones, M. and N. Sakimura, "JSON Web Key (JWK) + Thumbprint", RFC 7638, DOI 10.17487/RFC7638, September + 2015, . + + [RYU] "Ryu floating point number serializing algorithm", commit + 27d3c55, May 2020, . + + [V8] Google LLC, "What is V8?", . + + [XMLDSIG] W3C, "XML Signature Syntax and Processing Version 1.1", + W3C Recommendation, April 2013, + . + +Appendix A. ECMAScript Sample Canonicalizer + + Below is an example of a JCS canonicalizer for usage with ECMAScript- + based systems: + + //////////////////////////////////////////////////////////// + // Since the primary purpose of this code is highlighting // + // the core of the JCS algorithm, error handling and // + // UTF-8 generation were not implemented. // + //////////////////////////////////////////////////////////// + var canonicalize = function(object) { + + var buffer = ''; + serialize(object); + return buffer; + + function serialize(object) { + if (object === null || typeof object !== 'object' || + object.toJSON != null) { + ///////////////////////////////////////////////// + // Primitive type or toJSON, use "JSON" // + ///////////////////////////////////////////////// + buffer += JSON.stringify(object); + + } else if (Array.isArray(object)) { + ///////////////////////////////////////////////// + // Array - Maintain element order // + ///////////////////////////////////////////////// + buffer += '['; + let next = false; + object.forEach((element) => { + if (next) { + buffer += ','; + } + next = true; + ///////////////////////////////////////// + // Array element - Recursive expansion // + ///////////////////////////////////////// + serialize(element); + }); + buffer += ']'; + + } else { + ///////////////////////////////////////////////// + // Object - Sort properties before serializing // + ///////////////////////////////////////////////// + buffer += '{'; + let next = false; + Object.keys(object).sort().forEach((property) => { + if (next) { + buffer += ','; + } + next = true; + ///////////////////////////////////////////// + // Property names are strings, use "JSON" // + ///////////////////////////////////////////// + buffer += JSON.stringify(property); + buffer += ':'; + ////////////////////////////////////////// + // Property value - Recursive expansion // + ////////////////////////////////////////// + serialize(object[property]); + }); + buffer += '}'; + } + } + }; + +Appendix B. Number Serialization Samples + + The following table holds a set of ECMAScript-compatible number + serialization samples, including some edge cases. The column "IEEE + 754" refers to the internal ECMAScript representation of the "Number" + data type, which is based on the IEEE 754 [IEEE754] standard using + 64-bit (double-precision) values, here expressed in hexadecimal. + + +==================+===========================+====================+ + | IEEE 754 | JSON Representation | Comment | + +==================+===========================+====================+ + | 0000000000000000 | 0 | Zero | + +------------------+---------------------------+--------------------+ + | 8000000000000000 | 0 | Minus zero | + +------------------+---------------------------+--------------------+ + | 0000000000000001 | 5e-324 | Min pos number | + +------------------+---------------------------+--------------------+ + | 8000000000000001 | -5e-324 | Min neg number | + +------------------+---------------------------+--------------------+ + | 7fefffffffffffff | 1.7976931348623157e+308 | Max pos number | + +------------------+---------------------------+--------------------+ + | ffefffffffffffff | -1.7976931348623157e+308 | Max neg number | + +------------------+---------------------------+--------------------+ + | 4340000000000000 | 9007199254740992 | Max pos int (1) | + +------------------+---------------------------+--------------------+ + | c340000000000000 | -9007199254740992 | Max neg int (1) | + +------------------+---------------------------+--------------------+ + | 4430000000000000 | 295147905179352830000 | ~2**68 (2) | + +------------------+---------------------------+--------------------+ + | 7fffffffffffffff | | NaN (3) | + +------------------+---------------------------+--------------------+ + | 7ff0000000000000 | | Infinity (3) | + +------------------+---------------------------+--------------------+ + | 44b52d02c7e14af5 | 9.999999999999997e+22 | | + +------------------+---------------------------+--------------------+ + | 44b52d02c7e14af6 | 1e+23 | | + +------------------+---------------------------+--------------------+ + | 44b52d02c7e14af7 | 1.0000000000000001e+23 | | + +------------------+---------------------------+--------------------+ + | 444b1ae4d6e2ef4e | 999999999999999700000 | | + +------------------+---------------------------+--------------------+ + | 444b1ae4d6e2ef4f | 999999999999999900000 | | + +------------------+---------------------------+--------------------+ + | 444b1ae4d6e2ef50 | 1e+21 | | + +------------------+---------------------------+--------------------+ + | 3eb0c6f7a0b5ed8c | 9.999999999999997e-7 | | + +------------------+---------------------------+--------------------+ + | 3eb0c6f7a0b5ed8d | 0.000001 | | + +------------------+---------------------------+--------------------+ + | 41b3de4355555553 | 333333333.3333332 | | + +------------------+---------------------------+--------------------+ + | 41b3de4355555554 | 333333333.33333325 | | + +------------------+---------------------------+--------------------+ + | 41b3de4355555555 | 333333333.3333333 | | + +------------------+---------------------------+--------------------+ + | 41b3de4355555556 | 333333333.3333334 | | + +------------------+---------------------------+--------------------+ + | 41b3de4355555557 | 333333333.33333343 | | + +------------------+---------------------------+--------------------+ + | becbf647612f3696 | -0.0000033333333333333333 | | + +------------------+---------------------------+--------------------+ + | 43143ff3c1cb0959 | 1424953923781206.2 | Round to even (4) | + +------------------+---------------------------+--------------------+ + + Table 1: ECMAScript-Compatible JSON Number Serialization Samples + + Notes: + + (1) For maximum compliance with the ECMAScript "JSON" object, values + that are to be interpreted as true integers SHOULD be in the + range -9007199254740991 to 9007199254740991. However, how + numbers are used in applications does not affect the JCS + algorithm. + + (2) Although a set of specific integers like 2**68 could be regarded + as having extended precision, the JCS/ECMAScript number + serialization algorithm does not take this into consideration. + + (3) Values out of range are not permitted in JSON. See + Section 3.2.2.3. + + (4) This number is exactly 1424953923781206.25 but will, after the + "Note 2" rule mentioned in Section 3.2.2.3, be truncated and + rounded to the closest even value. + + For a more exhaustive validation of a JCS number serializer, you may + test against a file (currently) available in the development portal + (see Appendix I) containing a large set of sample values. Another + option is running V8 [V8] as a live reference together with a program + generating a substantial amount of random IEEE 754 values. + +Appendix C. Canonicalized JSON as "Wire Format" + + Since the result from the canonicalization process (see + Section 3.2.4) is fully valid JSON, it can also be used as "Wire + Format". However, this is just an option since cryptographic schemes + based on JCS, in most cases, would not depend on that externally + supplied JSON data already being canonicalized. + + In fact, the ECMAScript standard way of serializing objects using + "JSON.stringify()" produces a more "logical" format, where properties + are kept in the order they were created or received. The example + below shows an address record that could benefit from ECMAScript + standard serialization: + + { + "name": "John Doe", + "address": "2000 Sunset Boulevard", + "city": "Los Angeles", + "zip": "90001", + "state": "CA" + } + + Using canonicalization, the properties above would be output in the + order "address", "city", "name", "state", and "zip", which adds + fuzziness to the data from a human (developer or technical support) + perspective. Canonicalization also converts JSON data into a single + line of text, which may be less than ideal for debugging and logging. + +Appendix D. Dealing with Big Numbers + + There are several issues associated with the JSON number type, here + illustrated by the following sample object: + + { + "giantNumber": 1.4e+9999, + "payMeThis": 26000.33, + "int64Max": 9223372036854775807 + } + + Although the sample above conforms to JSON [RFC8259], applications + would normally use different native data types for storing + "giantNumber" and "int64Max". In addition, monetary data like + "payMeThis" would presumably not rely on floating-point data types + due to rounding issues with respect to decimal arithmetic. + + The established way of handling this kind of "overloading" of the + JSON number type (at least in an extensible manner) is through + mapping mechanisms, instructing parsers what to do with different + properties based on their name. However, this greatly limits the + value of using the JSON number type outside of its original, somewhat + constrained JavaScript context. The ECMAScript "JSON" object does + not support mappings to the JSON number type either. + + Due to the above, numbers that do not have a natural place in the + current JSON ecosystem MUST be wrapped using the JSON string type. + This is close to a de facto standard for open systems. This is also + applicable for other data types that do not have direct support in + JSON, like "DateTime" objects as described in Appendix E. + + Aided by a system using the JSON string type, be it programmatic like + + var obj = JSON.parse('{"giantNumber": "1.4e+9999"}'); + var biggie = new BigNumber(obj.giantNumber); + + or declarative schemes like OpenAPI [OPENAPI], JCS imposes no limits + on applications, including when using ECMAScript. + +Appendix E. String Subtype Handling + + Due to the limited set of data types featured in JSON, the JSON + string type is commonly used for holding subtypes. This can, + depending on JSON parsing method, lead to interoperability problems, + which MUST be dealt with by JCS-compliant applications targeting a + wider audience. + + Assume you want to parse a JSON object where the schema designer + assigned the property "big" for holding a "BigInt" subtype and "time" + for holding a "DateTime" subtype, while "val" is supposed to be a + JSON number compliant with JCS. The following example shows such an + object: + + { + "time": "2019-01-28T07:45:10Z", + "big": "055", + "val": 3.5 + } + + Parsing of this object can be accomplished by the following + ECMAScript statement: + + var object = JSON.parse(JSON_object_featured_as_a_string); + + After parsing, the actual data can be extracted, which for subtypes, + also involves a conversion step using the result of the parsing + process (an ECMAScript object) as input: + + ... = new Date(object.time); // Date object + ... = BigInt(object.big); // Big integer + ... = object.val; // JSON/JS number + + Note that the "BigInt" data type is currently only natively supported + by V8 [V8]. + + Canonicalization of "object" using the sample code in Appendix A + would return the following string: + + {"big":"055","time":"2019-01-28T07:45:10Z","val":3.5} + + Although this is (with respect to JCS) technically correct, there is + another way of parsing JSON data, which also can be used with + ECMAScript as shown below: + + // "BigInt" requires the following code to become JSON serializable + BigInt.prototype.toJSON = function() { + return this.toString(); + }; + + // JSON parsing using a "stream"-based method + var object = JSON.parse(JSON_object_featured_as_a_string, + (k,v) => k == 'time' ? new Date(v) : k == 'big' ? BigInt(v) : v + ); + + If you now apply the canonicalizer in Appendix A to "object", the + following string would be generated: + + {"big":"55","time":"2019-01-28T07:45:10.000Z","val":3.5} + + In this case, the string arguments for "big" and "time" have changed + with respect to the original, presumably making an application + depending on JCS fail. + + The reason for the deviation is that in stream- and schema-based JSON + parsers, the original string argument is typically replaced on the + fly by the native subtype that, when serialized, may exhibit a + different and platform-dependent pattern. + + That is, stream- and schema-based parsing MUST treat subtypes as + "pure" (immutable) JSON string types and perform the actual + conversion to the designated native type in a subsequent step. In + modern programming platforms like Go, Java, and C#, this can be + achieved with moderate efforts by combining annotations, getters, and + setters. Below is an example in C#/Json.NET showing a part of a + class that is serializable as a JSON object: + + // The "pure" string solution uses a local + // string variable for JSON serialization while + // exposing another type to the application + [JsonProperty("amount")] + private string _amount; + + [JsonIgnore] + public decimal Amount { + get { return decimal.Parse(_amount); } + set { _amount = value.ToString(); } + } + + In an application, "Amount" can be accessed as any other property + while it is actually represented by a quoted string in JSON contexts. + + Note: The example above also addresses the constraints on numeric + data implied by I-JSON (the C# "decimal" data type has quite + different characteristics compared to IEEE 754 double precision). + +E.1. Subtypes in Arrays + + Since the JSON array construct permits mixing arbitrary JSON data + types, custom parsing and serialization code may be required to cope + with subtypes anyway. + +Appendix F. Implementation Guidelines + + The optimal solution is integrating support for JCS directly in JSON + serializers (parsers need no changes). That is, canonicalization + would just be an additional "mode" for a JSON serializer. However, + this is currently not the case. Fortunately, JCS support can be + introduced through externally supplied canonicalizer software acting + as a post processor to existing JSON serializers. This arrangement + also relieves the JCS implementer from having to deal with how + underlying data is to be represented in JSON. + + The post processor concept enables signature creation schemes like + the following: + + 1. Create the data to be signed. + + 2. Serialize the data using existing JSON tools. + + 3. Let the external canonicalizer process the serialized data and + return canonicalized result data. + + 4. Sign the canonicalized data. + + 5. Add the resulting signature value to the original JSON data + through a designated signature property. + + 6. Serialize the completed (now signed) JSON object using existing + JSON tools. + + A compatible signature verification scheme would then be as follows: + + 1. Parse the signed JSON data using existing JSON tools. + + 2. Read and save the signature value from the designated signature + property. + + 3. Remove the signature property from the parsed JSON object. + + 4. Serialize the remaining JSON data using existing JSON tools. + + 5. Let the external canonicalizer process the serialized data and + return canonicalized result data. + + 6. Verify that the canonicalized data matches the saved signature + value using the algorithm and key used for creating the + signature. + + A canonicalizer like above is effectively only a "filter", + potentially usable with a multitude of quite different cryptographic + schemes. + + Using a JSON serializer with integrated JCS support, the + serialization performed before the canonicalization step could be + eliminated for both processes. + +Appendix G. Open-Source Implementations + + The following open-source implementations have been verified to be + compatible with JCS: + + * JavaScript: + + * Java: + + * Go: + + * .NET/C#: + + * Python: + +Appendix H. Other JSON Canonicalization Efforts + + There are (and have been) other efforts creating "Canonical JSON". + Below is a list of URLs to some of them: + + * + + * + + * + + The listed efforts all build on text-level JSON-to-JSON + transformations. The primary feature of text-level canonicalization + is that it can be made neutral to the flavor of JSON used. However, + such schemes also imply major changes to the JSON parsing process, + which is a likely hurdle for adoption. Albeit at the expense of + certain JSON and application constraints, JCS was designed to be + compatible with existing JSON tools. + +Appendix I. Development Portal + + The JCS specification is currently developed at: + . + + JCS source code and extensive test data is available at: + . + +Acknowledgements + + Building on ECMAScript number serialization was originally proposed + by James Manger. This ultimately led to the adoption of the entire + ECMAScript serialization scheme for JSON primitives. + + Other people who have contributed with valuable input to this + specification include Scott Ananian, Tim Bray, Ben Campbell, Adrian + Farell, Richard Gibson, Bron Gondwana, John-Mark Gurney, Mike Jones, + John Levine, Mark Miller, Matthew Miller, Mark Nottingham, Mike + Samuel, Jim Schaad, Robert Tupelo-Schneck, and Michal Wadas. + + For carrying out real-world concept verification, the software and + support for number serialization provided by Ulf Adams, Tanner + Gooding, and Remy Oudompheng was very helpful. + +Authors' Addresses + + Anders Rundgren + Independent + Montpellier + France + + Email: anders.rundgren.net@gmail.com + URI: https://www.linkedin.com/in/andersrundgren/ + + + Bret Jordan + Broadcom + 1320 Ridder Park Drive + San Jose, CA 95131 + United States of America + + Email: bret.jordan@broadcom.com + + + Samuel Erdtman + Spotify AB + Birger Jarlsgatan 61, 4tr + SE-113 56 Stockholm + Sweden + + Email: erdtman@spotify.com diff --git a/app/specs/standards/texts/ded8fa1754ab1566fd72611c9d5bcde931cd2bdf8351889e2ef5b50efdf1eed4 b/app/specs/standards/texts/ded8fa1754ab1566fd72611c9d5bcde931cd2bdf8351889e2ef5b50efdf1eed4 new file mode 100644 index 00000000..b517085c --- /dev/null +++ b/app/specs/standards/texts/ded8fa1754ab1566fd72611c9d5bcde931cd2bdf8351889e2ef5b50efdf1eed4 @@ -0,0 +1,1011 @@ + + + + + + +Internet Engineering Task Force (IETF) P. Bryan, Ed. +Request for Comments: 6902 Salesforce.com +Category: Standards Track M. Nottingham, Ed. +ISSN: 2070-1721 Akamai + April 2013 + + + JavaScript Object Notation (JSON) Patch + +Abstract + + JSON Patch defines a JSON document structure for expressing a + sequence of operations to apply to a JavaScript Object Notation + (JSON) document; it is suitable for use with the HTTP PATCH method. + The "application/json-patch+json" media type is used to identify such + patch documents. + +Status of This Memo + + This is an Internet Standards Track document. + + This document is a product of the Internet Engineering Task Force + (IETF). It represents the consensus of the IETF community. It has + received public review and has been approved for publication by the + Internet Engineering Steering Group (IESG). Further information on + Internet Standards is available in Section 2 of RFC 5741. + + Information about the current status of this document, any errata, + and how to provide feedback on it may be obtained at + http://www.rfc-editor.org/info/rfc6902. + +Copyright Notice + + Copyright (c) 2013 IETF Trust and the persons identified as the + document authors. All rights reserved. + + This document is subject to BCP 78 and the IETF Trust's Legal + Provisions Relating to IETF Documents + (http://trustee.ietf.org/license-info) in effect on the date of + publication of this document. Please review these documents + carefully, as they describe your rights and restrictions with respect + to this document. Code Components extracted from this document must + include Simplified BSD License text as described in Section 4.e of + the Trust Legal Provisions and are provided without warranty as + described in the Simplified BSD License. + + + + + + +Bryan & Nottingham Standards Track [Page 1] + +RFC 6902 JSON Patch April 2013 + + +Table of Contents + + 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 3 + 2. Conventions . . . . . . . . . . . . . . . . . . . . . . . . . 3 + 3. Document Structure . . . . . . . . . . . . . . . . . . . . . . 3 + 4. Operations . . . . . . . . . . . . . . . . . . . . . . . . . . 4 + 4.1. add . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 + 4.2. remove . . . . . . . . . . . . . . . . . . . . . . . . . . 6 + 4.3. replace . . . . . . . . . . . . . . . . . . . . . . . . . 6 + 4.4. move . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 + 4.5. copy . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 + 4.6. test . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 + 5. Error Handling . . . . . . . . . . . . . . . . . . . . . . . . 8 + 6. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 9 + 7. Security Considerations . . . . . . . . . . . . . . . . . . . 10 + 8. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . 10 + 9. References . . . . . . . . . . . . . . . . . . . . . . . . . . 10 + 9.1. Normative References . . . . . . . . . . . . . . . . . . . 10 + 9.2. Informative References . . . . . . . . . . . . . . . . . . 10 + Appendix A. Examples . . . . . . . . . . . . . . . . . . . . . . 12 + A.1. Adding an Object Member . . . . . . . . . . . . . . . . . 12 + A.2. Adding an Array Element . . . . . . . . . . . . . . . . . 12 + A.3. Removing an Object Member . . . . . . . . . . . . . . . . 12 + A.4. Removing an Array Element . . . . . . . . . . . . . . . . 13 + A.5. Replacing a Value . . . . . . . . . . . . . . . . . . . . 13 + A.6. Moving a Value . . . . . . . . . . . . . . . . . . . . . . 14 + A.7. Moving an Array Element . . . . . . . . . . . . . . . . . 14 + A.8. Testing a Value: Success . . . . . . . . . . . . . . . . . 15 + A.9. Testing a Value: Error . . . . . . . . . . . . . . . . . . 15 + A.10. Adding a Nested Member Object . . . . . . . . . . . . . . 15 + A.11. Ignoring Unrecognized Elements . . . . . . . . . . . . . . 16 + A.12. Adding to a Nonexistent Target . . . . . . . . . . . . . . 16 + A.13. Invalid JSON Patch Document . . . . . . . . . . . . . . . 17 + A.14. ~ Escape Ordering . . . . . . . . . . . . . . . . . . . . 17 + A.15. Comparing Strings and Numbers . . . . . . . . . . . . . . 17 + A.16. Adding an Array Value . . . . . . . . . . . . . . . . . . 18 + + + + + + + + + + + + + + + +Bryan & Nottingham Standards Track [Page 2] + +RFC 6902 JSON Patch April 2013 + + +1. Introduction + + JavaScript Object Notation (JSON) [RFC4627] is a common format for + the exchange and storage of structured data. HTTP PATCH [RFC5789] + extends the Hypertext Transfer Protocol (HTTP) [RFC2616] with a + method to perform partial modifications to resources. + + JSON Patch is a format (identified by the media type "application/ + json-patch+json") for expressing a sequence of operations to apply to + a target JSON document; it is suitable for use with the HTTP PATCH + method. + + This format is also potentially useful in other cases in which it is + necessary to make partial updates to a JSON document or to a data + structure that has similar constraints (i.e., they can be serialized + as an object or an array using the JSON grammar). + +2. Conventions + + The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", + "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this + document are to be interpreted as described in RFC 2119 [RFC2119]. + +3. Document Structure + + A JSON Patch document is a JSON [RFC4627] document that represents an + array of objects. Each object represents a single operation to be + applied to the target JSON document. + + The following is an example JSON Patch document, transferred in an + HTTP PATCH request: + + PATCH /my/data HTTP/1.1 + Host: example.org + Content-Length: 326 + Content-Type: application/json-patch+json + If-Match: "abc123" + + [ + { "op": "test", "path": "/a/b/c", "value": "foo" }, + { "op": "remove", "path": "/a/b/c" }, + { "op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ] }, + { "op": "replace", "path": "/a/b/c", "value": 42 }, + { "op": "move", "from": "/a/b/c", "path": "/a/b/d" }, + { "op": "copy", "from": "/a/b/d", "path": "/a/b/e" } + ] + + + + + +Bryan & Nottingham Standards Track [Page 3] + +RFC 6902 JSON Patch April 2013 + + + Evaluation of a JSON Patch document begins against a target JSON + document. Operations are applied sequentially in the order they + appear in the array. Each operation in the sequence is applied to + the target document; the resulting document becomes the target of the + next operation. Evaluation continues until all operations are + successfully applied or until an error condition is encountered. + +4. Operations + + Operation objects MUST have exactly one "op" member, whose value + indicates the operation to perform. Its value MUST be one of "add", + "remove", "replace", "move", "copy", or "test"; other values are + errors. The semantics of each object is defined below. + + Additionally, operation objects MUST have exactly one "path" member. + That member's value is a string containing a JSON-Pointer value + [RFC6901] that references a location within the target document (the + "target location") where the operation is performed. + + The meanings of other operation object members are defined by + operation (see the subsections below). Members that are not + explicitly defined for the operation in question MUST be ignored + (i.e., the operation will complete as if the undefined member did not + appear in the object). + + Note that the ordering of members in JSON objects is not significant; + therefore, the following operation objects are equivalent: + + { "op": "add", "path": "/a/b/c", "value": "foo" } + { "path": "/a/b/c", "op": "add", "value": "foo" } + { "value": "foo", "path": "/a/b/c", "op": "add" } + + Operations are applied to the data structures represented by a JSON + document, i.e., after any unescaping (see [RFC4627], Section 2.5) + takes place. + +4.1. add + + The "add" operation performs one of the following functions, + depending upon what the target location references: + + o If the target location specifies an array index, a new value is + inserted into the array at the specified index. + + o If the target location specifies an object member that does not + already exist, a new member is added to the object. + + + + + +Bryan & Nottingham Standards Track [Page 4] + +RFC 6902 JSON Patch April 2013 + + + o If the target location specifies an object member that does exist, + that member's value is replaced. + + The operation object MUST contain a "value" member whose content + specifies the value to be added. + + For example: + + { "op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ] } + + When the operation is applied, the target location MUST reference one + of: + + o The root of the target document - whereupon the specified value + becomes the entire content of the target document. + + o A member to add to an existing object - whereupon the supplied + value is added to that object at the indicated location. If the + member already exists, it is replaced by the specified value. + + o An element to add to an existing array - whereupon the supplied + value is added to the array at the indicated location. Any + elements at or above the specified index are shifted one position + to the right. The specified index MUST NOT be greater than the + number of elements in the array. If the "-" character is used to + index the end of the array (see [RFC6901]), this has the effect of + appending the value to the array. + + Because this operation is designed to add to existing objects and + arrays, its target location will often not exist. Although the + pointer's error handling algorithm will thus be invoked, this + specification defines the error handling behavior for "add" pointers + to ignore that error and add the value as specified. + + However, the object itself or an array containing it does need to + exist, and it remains an error for that not to be the case. For + example, an "add" with a target location of "/a/b" starting with this + document: + + { "a": { "foo": 1 } } + + is not an error, because "a" exists, and "b" will be added to its + value. It is an error in this document: + + { "q": { "bar": 2 } } + + because "a" does not exist. + + + + +Bryan & Nottingham Standards Track [Page 5] + +RFC 6902 JSON Patch April 2013 + + +4.2. remove + + The "remove" operation removes the value at the target location. + + The target location MUST exist for the operation to be successful. + + For example: + + { "op": "remove", "path": "/a/b/c" } + + If removing an element from an array, any elements above the + specified index are shifted one position to the left. + +4.3. replace + + The "replace" operation replaces the value at the target location + with a new value. The operation object MUST contain a "value" member + whose content specifies the replacement value. + + The target location MUST exist for the operation to be successful. + + For example: + + { "op": "replace", "path": "/a/b/c", "value": 42 } + + This operation is functionally identical to a "remove" operation for + a value, followed immediately by an "add" operation at the same + location with the replacement value. + +4.4. move + + The "move" operation removes the value at a specified location and + adds it to the target location. + + The operation object MUST contain a "from" member, which is a string + containing a JSON Pointer value that references the location in the + target document to move the value from. + + The "from" location MUST exist for the operation to be successful. + + For example: + + { "op": "move", "from": "/a/b/c", "path": "/a/b/d" } + + This operation is functionally identical to a "remove" operation on + the "from" location, followed immediately by an "add" operation at + the target location with the value that was just removed. + + + + +Bryan & Nottingham Standards Track [Page 6] + +RFC 6902 JSON Patch April 2013 + + + The "from" location MUST NOT be a proper prefix of the "path" + location; i.e., a location cannot be moved into one of its children. + +4.5. copy + + The "copy" operation copies the value at a specified location to the + target location. + + The operation object MUST contain a "from" member, which is a string + containing a JSON Pointer value that references the location in the + target document to copy the value from. + + The "from" location MUST exist for the operation to be successful. + + For example: + + { "op": "copy", "from": "/a/b/c", "path": "/a/b/e" } + + This operation is functionally identical to an "add" operation at the + target location using the value specified in the "from" member. + +4.6. test + + The "test" operation tests that a value at the target location is + equal to a specified value. + + The operation object MUST contain a "value" member that conveys the + value to be compared to the target location's value. + + The target location MUST be equal to the "value" value for the + operation to be considered successful. + + Here, "equal" means that the value at the target location and the + value conveyed by "value" are of the same JSON type, and that they + are considered equal by the following rules for that type: + + o strings: are considered equal if they contain the same number of + Unicode characters and their code points are byte-by-byte equal. + + o numbers: are considered equal if their values are numerically + equal. + + o arrays: are considered equal if they contain the same number of + values, and if each value can be considered equal to the value at + the corresponding position in the other array, using this list of + type-specific rules. + + + + + +Bryan & Nottingham Standards Track [Page 7] + +RFC 6902 JSON Patch April 2013 + + + o objects: are considered equal if they contain the same number of + members, and if each member can be considered equal to a member in + the other object, by comparing their keys (as strings) and their + values (using this list of type-specific rules). + + o literals (false, true, and null): are considered equal if they are + the same. + + Note that the comparison that is done is a logical comparison; e.g., + whitespace between the member values of an array is not significant. + + Also, note that ordering of the serialization of object members is + not significant. + + For example: + + { "op": "test", "path": "/a/b/c", "value": "foo" } + +5. Error Handling + + If a normative requirement is violated by a JSON Patch document, or + if an operation is not successful, evaluation of the JSON Patch + document SHOULD terminate and application of the entire patch + document SHALL NOT be deemed successful. + + See [RFC5789], Section 2.2 for considerations regarding handling + errors when JSON Patch is used with the HTTP PATCH method, including + suggested status codes to use to indicate various conditions. + + Note that the HTTP PATCH method is atomic, as per [RFC5789]. + Therefore, the following patch would result in no changes being made + to the document at all (because the "test" operation results in an + error): + + [ + { "op": "replace", "path": "/a/b/c", "value": 42 }, + { "op": "test", "path": "/a/b/c", "value": "C" } + ] + + + + + + + + + + + + + +Bryan & Nottingham Standards Track [Page 8] + +RFC 6902 JSON Patch April 2013 + + +6. IANA Considerations + + The Internet media type for a JSON Patch document is application/ + json-patch+json. + + Type name: application + + Subtype name: json-patch+json + + Required parameters: none + + Optional parameters: none + + Encoding considerations: binary + + Security considerations: + See Security Considerations in Section 7. + + Interoperability considerations: N/A + + Published specification: + RFC 6902 + + Applications that use this media type: + Applications that manipulate JSON documents. + + Additional information: + + Magic number(s): N/A + + File extension(s): .json-patch + + Macintosh file type code(s): TEXT + + Person & email address to contact for further information: + Paul C. Bryan + + Intended usage: COMMON + + Restrictions on usage: none + + Author: Paul C. Bryan + + Change controller: IETF + + + + + + + +Bryan & Nottingham Standards Track [Page 9] + +RFC 6902 JSON Patch April 2013 + + +7. Security Considerations + + This specification has the same security considerations as JSON + [RFC4627] and JSON-Pointer [RFC6901]. + + A few older Web browsers can be coerced into loading an arbitrary + JSON document whose root is an array, leading to a situation in which + a JSON Patch document containing sensitive information could be + exposed to attackers, even if access is authenticated. This is known + as a Cross-Site Request Forgery (CSRF) attack [CSRF]. + + However, such browsers are not widely used (at the time of writing, + it is estimated that they are used in less than 1% of the market). + Publishers who are nevertheless concerned about this attack are + advised to avoid making such documents available with HTTP GET. + +8. Acknowledgements + + The following individuals contributed ideas, feedback and wording to + this specification: + + Mike Acar, Mike Amundsen, Cyrus Daboo, Paul Davis, Stefan Koegl, + Murray S. Kucherawy, Dean Landolt, Randall Leeds, James Manger, + Julian Reschke, James Snell, Eli Stevens, and Henry S. Thompson. + + The structure of a JSON Patch document was influenced by the XML + Patch document specification [RFC5261]. + +9. References + +9.1. Normative References + + [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate + Requirement Levels", BCP 14, RFC 2119, March 1997. + + [RFC4627] Crockford, D., "The application/json Media Type for + JavaScript Object Notation (JSON)", RFC 4627, July 2006. + + [RFC6901] Bryan, P., Ed., Zyp, K., and M. Nottingham, Ed., + "JavaScript Object Notation (JSON) Pointer", RFC 6901, + April 2013. + +9.2. Informative References + + [CSRF] Barth, A., Jackson, C., and J. Mitchell, "Robust Defenses + for Cross-Site Request Forgery", ACM Conference + on Computer and Communications Security, October 2008, + . + + + +Bryan & Nottingham Standards Track [Page 10] + +RFC 6902 JSON Patch April 2013 + + + [RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., + Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext + Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999. + + [RFC5261] Urpalainen, J., "An Extensible Markup Language (XML) Patch + Operations Framework Utilizing XML Path Language (XPath) + Selectors", RFC 5261, September 2008. + + [RFC5789] Dusseault, L. and J. Snell, "PATCH Method for HTTP", + RFC 5789, March 2010. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Bryan & Nottingham Standards Track [Page 11] + +RFC 6902 JSON Patch April 2013 + + +Appendix A. Examples + +A.1. Adding an Object Member + + An example target JSON document: + + { "foo": "bar"} + + A JSON Patch document: + + [ + { "op": "add", "path": "/baz", "value": "qux" } + ] + + The resulting JSON document: + + { + "baz": "qux", + "foo": "bar" + } + +A.2. Adding an Array Element + + An example target JSON document: + + { "foo": [ "bar", "baz" ] } + + A JSON Patch document: + + [ + { "op": "add", "path": "/foo/1", "value": "qux" } + ] + + The resulting JSON document: + + { "foo": [ "bar", "qux", "baz" ] } + +A.3. Removing an Object Member + + An example target JSON document: + + { + "baz": "qux", + "foo": "bar" + } + + + + + + +Bryan & Nottingham Standards Track [Page 12] + +RFC 6902 JSON Patch April 2013 + + + A JSON Patch document: + + [ + { "op": "remove", "path": "/baz" } + ] + + The resulting JSON document: + + { "foo": "bar" } + +A.4. Removing an Array Element + + An example target JSON document: + + { "foo": [ "bar", "qux", "baz" ] } + + A JSON Patch document: + + [ + { "op": "remove", "path": "/foo/1" } + ] + + The resulting JSON document: + + { "foo": [ "bar", "baz" ] } + +A.5. Replacing a Value + + An example target JSON document: + + { + "baz": "qux", + "foo": "bar" + } + + A JSON Patch document: + + [ + { "op": "replace", "path": "/baz", "value": "boo" } + ] + + The resulting JSON document: + + { + "baz": "boo", + "foo": "bar" + } + + + + +Bryan & Nottingham Standards Track [Page 13] + +RFC 6902 JSON Patch April 2013 + + +A.6. Moving a Value + + An example target JSON document: + + { + "foo": { + "bar": "baz", + "waldo": "fred" + }, + "qux": { + "corge": "grault" + } + } + + A JSON Patch document: + + [ + { "op": "move", "from": "/foo/waldo", "path": "/qux/thud" } + ] + + The resulting JSON document: + + { + "foo": { + "bar": "baz" + }, + "qux": { + "corge": "grault", + "thud": "fred" + } + } + +A.7. Moving an Array Element + + An example target JSON document: + + { "foo": [ "all", "grass", "cows", "eat" ] } + + A JSON Patch document: + + [ + { "op": "move", "from": "/foo/1", "path": "/foo/3" } + ] + + The resulting JSON document: + + { "foo": [ "all", "cows", "eat", "grass" ] } + + + + +Bryan & Nottingham Standards Track [Page 14] + +RFC 6902 JSON Patch April 2013 + + +A.8. Testing a Value: Success + + An example target JSON document: + + { + "baz": "qux", + "foo": [ "a", 2, "c" ] + } + + A JSON Patch document that will result in successful evaluation: + + [ + { "op": "test", "path": "/baz", "value": "qux" }, + { "op": "test", "path": "/foo/1", "value": 2 } + ] + +A.9. Testing a Value: Error + + An example target JSON document: + + { "baz": "qux" } + + A JSON Patch document that will result in an error condition: + + [ + { "op": "test", "path": "/baz", "value": "bar" } + ] + +A.10. Adding a Nested Member Object + + An example target JSON document: + + { "foo": "bar" } + + A JSON Patch document: + + [ + { "op": "add", "path": "/child", "value": { "grandchild": { } } } + ] + + + + + + + + + + + + +Bryan & Nottingham Standards Track [Page 15] + +RFC 6902 JSON Patch April 2013 + + + The resulting JSON document: + + { + "foo": "bar", + "child": { + "grandchild": { + } + } + } + +A.11. Ignoring Unrecognized Elements + + An example target JSON document: + + { "foo": "bar" } + + A JSON Patch document: + + [ + { "op": "add", "path": "/baz", "value": "qux", "xyz": 123 } + ] + + The resulting JSON document: + + { + "foo": "bar", + "baz": "qux" + } + +A.12. Adding to a Nonexistent Target + + An example target JSON document: + + { "foo": "bar" } + + A JSON Patch document: + + [ + { "op": "add", "path": "/baz/bat", "value": "qux" } + ] + + This JSON Patch document, applied to the target JSON document above, + would result in an error (therefore, it would not be applied), + because the "add" operation's target location that references neither + the root of the document, nor a member of an existing object, nor a + member of an existing array. + + + + + +Bryan & Nottingham Standards Track [Page 16] + +RFC 6902 JSON Patch April 2013 + + +A.13. Invalid JSON Patch Document + + A JSON Patch document: + + [ + { "op": "add", "path": "/baz", "value": "qux", "op": "remove" } + ] + + This JSON Patch document cannot be treated as an "add" operation, + because it contains a later "op":"remove" element. JSON requires + that object member names be unique with a "SHOULD" requirement, and + there is no standard error handling for duplicates. + +A.14. ~ Escape Ordering + + An example target JSON document: + + { + "/": 9, + "~1": 10 + } + + A JSON Patch document: + + [ + {"op": "test", "path": "/~01", "value": 10} + ] + + The resulting JSON document: + + { + "/": 9, + "~1": 10 + } + +A.15. Comparing Strings and Numbers + + An example target JSON document: + + { + "/": 9, + "~1": 10 + } + + + + + + + + +Bryan & Nottingham Standards Track [Page 17] + +RFC 6902 JSON Patch April 2013 + + + A JSON Patch document: + + [ + {"op": "test", "path": "/~01", "value": "10"} + ] + + This results in an error, because the test fails. The document value + is numeric, whereas the value being tested for is a string. + +A.16. Adding an Array Value + + An example target JSON document: + + { "foo": ["bar"] } + + A JSON Patch document: + + [ + { "op": "add", "path": "/foo/-", "value": ["abc", "def"] } + ] + + The resulting JSON document: + + { "foo": ["bar", ["abc", "def"]] } + +Authors' Addresses + + Paul C. Bryan (editor) + Salesforce.com + + Phone: +1 604 783 1481 + EMail: pbryan@anode.ca + + + Mark Nottingham (editor) + Akamai + + EMail: mnot@mnot.net + + + + + + + + + + + + + +Bryan & Nottingham Standards Track [Page 18] + diff --git a/app/src/PrismSnapshot.lex.tex b/app/src/PrismSnapshot.lex.tex new file mode 100644 index 00000000..fbc86847 --- /dev/null +++ b/app/src/PrismSnapshot.lex.tex @@ -0,0 +1,1883 @@ +\begin{lexlean}{PrismSnapshot} +\useglossary{lexlean.std.bool@1.2.0} +\useglossary{lexlean.std.nat@1.2.0} +\useglossary{prism.arch@1.0.0} +\importmodule{Foundation.Bytes} +\title{system state} +\begin{semanticmodule} +definition{ + name: stByteOr, + parameters: [s : Bytes, i : Nat], + result: Nat, + body: (match (Foundation.Bytes::byteAt s i) + | Option.none => 0 + | Option.some b => (prim to_nat b : Nat)), + axioms: [Quot.sound, propext] +} + +definition{ + name: stSameBytes, + parameters: [left : Bytes, right : Bytes], + result: Bool, + body: (prim equal (prim compare_bytes left right : Ordering) (prim compare_bytes 0x00 0x00 : Ordering) : Bool), + axioms: [propext] +} + +definition{ + name: sjAt, + parameters: [s : Bytes, i : Nat], + result: Nat, + body: (stByteOr s i), + axioms: [Quot.sound, propext] +} + +definition{ + name: sjIsSpace, + parameters: [b : Nat], + result: Bool, + body: ((b =? 32) || ((b =? 10) || ((b =? 13) || (b =? 9)))) +} + +definition{ + name: sjSkipSpace, + parameters: [s : Bytes, i : Nat, fuel : Nat], + result: Nat, + body: (match fuel + | Nat.zero => i + | Nat.succ rest => (if (sjIsSpace (sjAt s i)) then (sjSkipSpace s (i + 1) rest) else i)), + axioms: [Quot.sound, propext], + recursive_argument: fuel +} + +definition{ + name: sjSpace, + parameters: [s : Bytes, i : Nat], + result: Nat, + body: (sjSkipSpace s i (Foundation.Bytes::byteLength s)), + axioms: [Quot.sound, propext] +} + +definition{ + name: sjStringEndFrom, + parameters: [s : Bytes, i : Nat, fuel : Nat], + result: Nat, + body: (match fuel + | Nat.zero => i + | Nat.succ rest => (let b : Nat := (sjAt s i); (if (b =? 34) then i else (if (b =? 92) then (sjStringEndFrom s (i + 2) rest) else (if ((Foundation.Bytes::byteLength s) i + | Nat.succ rest => (let b : Nat := (sjAt s i); (if ((Foundation.Bytes::byteLength s) i + | Nat.succ rest => (let b : Nat := (sjAt s i); (if (((Foundation.Bytes::byteLength s) 0x + | Option.some b => b) +} + +definition{ + name: sjMemberFrom, + parameters: [s : Bytes, i : Nat, key : Bytes, fuel : Nat], + result: (Option Nat), + body: (match fuel + | Nat.zero => (ctor Option.none [Nat]) + | Nat.succ rest => (if ((sjAt s i) =? 34) then (let ke : Nat := (sjStringEnd s (i + 1)); (let colon : Nat := (sjSpace s (ke + 1)); (if ((sjAt s colon) =? 58) then (let v : Nat := (sjSpace s (colon + 1)); (if (stSameBytes (sjSpan s (i + 1) ke) key) then (ctor Option.some [Nat] v) else (let next : Nat := (sjSpace s (sjValueEnd s v)); (if ((sjAt s next) =? 44) then (sjMemberFrom s (sjSpace s (next + 1)) key rest) else (ctor Option.none [Nat]))))) else (ctor Option.none [Nat])))) else (ctor Option.none [Nat]))), + axioms: [Quot.sound, propext], + recursive_argument: fuel +} + +definition{ + name: sjMember, + parameters: [s : Bytes, i : Nat, key : Bytes], + result: (Option Nat), + body: (if ((sjAt s i) =? 123) then (sjMemberFrom s (sjSpace s (i + 1)) key (Foundation.Bytes::byteLength s)) else (ctor Option.none [Nat])), + axioms: [Quot.sound, propext] +} + +definition{ + name: sjElementFrom, + parameters: [s : Bytes, i : Nat, n : Nat, fuel : Nat], + result: (Option Nat), + body: (match fuel + | Nat.zero => (ctor Option.none [Nat]) + | Nat.succ rest => (if ((sjAt s i) =? 93) then (ctor Option.none [Nat]) else (match n + | Nat.zero => (ctor Option.some [Nat] i) + | Nat.succ m => (let next : Nat := (sjSpace s (sjValueEnd s i)); (if ((sjAt s next) =? 44) then (sjElementFrom s (sjSpace s (next + 1)) m rest) else (ctor Option.none [Nat])))))), + axioms: [Quot.sound, propext], + recursive_argument: fuel +} + +definition{ + name: sjElement, + parameters: [s : Bytes, i : Nat, n : Nat], + result: (Option Nat), + body: (if ((sjAt s i) =? 91) then (sjElementFrom s (sjSpace s (i + 1)) n (Foundation.Bytes::byteLength s)) else (ctor Option.none [Nat])), + axioms: [Quot.sound, propext] +} + +definition{ + name: sjCountFrom, + parameters: [s : Bytes, i : Nat, acc : Nat, fuel : Nat], + result: Nat, + body: (match fuel + | Nat.zero => acc + | Nat.succ rest => (if ((sjAt s i) =? 93) then acc else (let next : Nat := (sjSpace s (sjValueEnd s i)); (if ((sjAt s next) =? 44) then (sjCountFrom s (sjSpace s (next + 1)) (acc + 1) rest) else (acc + 1))))), + axioms: [Quot.sound, propext], + recursive_argument: fuel +} + +definition{ + name: sjCount, + parameters: [s : Bytes, i : Nat], + result: Nat, + body: (if ((sjAt s i) =? 91) then (sjCountFrom s (sjSpace s (i + 1)) 0 (Foundation.Bytes::byteLength s)) else 0), + axioms: [Quot.sound, propext] +} + +definition{ + name: sjEscaped, + parameters: [b : Nat], + result: (Option Bytes), + body: (if (b =? 110) then (ctor Option.some [Bytes] 0x0a) else (if (b =? 116) then (ctor Option.some [Bytes] 0x09) else (if (b =? 114) then (ctor Option.some [Bytes] 0x0d) else (if (b =? 34) then (ctor Option.some [Bytes] 0x22) else (if (b =? 92) then (ctor Option.some [Bytes] 0x5c) else (if (b =? 47) then (ctor Option.some [Bytes] 0x2f) else (if (b =? 98) then (ctor Option.some [Bytes] 0x08) else (if (b =? 102) then (ctor Option.some [Bytes] 0x0c) else (ctor Option.none [Bytes]))))))))) +} + +definition{ + name: sjRunEnd, + parameters: [s : Bytes, i : Nat, fuel : Nat], + result: Nat, + body: (match fuel + | Nat.zero => i + | Nat.succ rest => (let b : Nat := (sjAt s i); (if (((b =? 34) || (b =? 92)) || ((Foundation.Bytes::byteLength s) (ctor Option.none [Bytes]) + | Nat.succ rest => (let e : Nat := (sjRunEnd s i (Foundation.Bytes::byteLength s)); (let got : Bytes := (Foundation.Bytes::appendBytes acc (sjSpan s i e)); (if ((sjAt s e) =? 34) then (ctor Option.some [Bytes] got) else (if ((sjAt s e) =? 92) then (match (sjEscaped (sjAt s (e + 1))) + | Option.none => (ctor Option.none [Bytes]) + | Option.some c => (sjUnescapeFrom s (e + 2) (Foundation.Bytes::appendBytes got c) rest)) else (ctor Option.none [Bytes])))))), + axioms: [Quot.sound, propext], + recursive_argument: fuel +} + +definition{ + name: sjText, + parameters: [s : Bytes, i : Nat], + result: (Option Bytes), + body: (if ((sjAt s i) =? 34) then (sjUnescapeFrom s (i + 1) 0x (Foundation.Bytes::byteLength s)) else (ctor Option.none [Bytes])), + axioms: [Quot.sound, propext] +} + +definition{ + name: sjTextAt, + parameters: [s : Bytes, i : (Option Nat)], + result: Bytes, + body: (match i + | Option.none => 0x + | Option.some v => (match (sjText s v) | Option.none => 0x | Option.some b => b)), + axioms: [Quot.sound, propext] +} + +definition{ + name: sjMemberAt, + parameters: [s : Bytes, i : (Option Nat), key : Bytes], + result: (Option Nat), + body: (match i | Option.none => (ctor Option.none [Nat]) | Option.some v => (sjMember s v key)), + axioms: [Quot.sound, propext] +} + +definition{ + name: sjElementAt, + parameters: [s : Bytes, i : (Option Nat), n : Nat], + result: (Option Nat), + body: (match i | Option.none => (ctor Option.none [Nat]) | Option.some v => (sjElement s v n)), + axioms: [Quot.sound, propext] +} + +definition{ + name: sjCountAt, + parameters: [s : Bytes, i : (Option Nat)], + result: Nat, + body: (match i | Option.none => 0 | Option.some v => (sjCount s v)), + axioms: [Quot.sound, propext] +} + +definition{ + name: sjRoot, + parameters: [s : Bytes], + result: (Option Nat), + body: (ctor Option.some [Nat] (sjSpace s 0)), + axioms: [Quot.sound, propext] +} + +structure{ + name: JpHit, + type_parameters: [], + parameters: [], + fields: [{name: start, type: Nat}, {name: vstart, type: Nat}, {name: vend, type: Nat}] +} + +structure{ + name: JpTok, + type_parameters: [], + parameters: [], + fields: [{name: tok, type: Bytes}, {name: next, type: Nat}] +} + +structure{ + name: JpBest, + type_parameters: [], + parameters: [], + fields: [{name: key, type: Bytes}, {name: bstart, type: Nat}, {name: bend, type: Nat}] +} + +definition{ + name: jpAt, + parameters: [s : Bytes, i : Nat], + result: Nat, + body: (stByteOr s i), + axioms: [Quot.sound, propext] +} + +definition{ + name: jpLen, + parameters: [s : Bytes], + result: Nat, + body: (Foundation.Bytes::byteLength s) +} + +definition{ + name: jpCat, + parameters: [a : Bytes, b : Bytes], + result: Bytes, + body: (Foundation.Bytes::appendBytes a b) +} + +definition{ + name: jpSpan, + parameters: [s : Bytes, a : Nat, b : Nat], + result: Bytes, + body: (sjSpan s a b) +} + +definition{ + name: jpSame, + parameters: [a : Bytes, b : Bytes], + result: Bool, + body: (stSameBytes a b), + axioms: [propext] +} + +definition{ + name: jpLess, + parameters: [a : Bytes, b : Bytes], + result: Bool, + body: (prim equal (prim compare_bytes a b : Ordering) (prim compare_bytes 0x00 0x01 : Ordering) : Bool), + axioms: [propext] +} + +definition{ + name: jpByte, + parameters: [n : Nat], + result: Bytes, + body: (jpSpan 0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff n (n + 1)) +} + +definition{ + name: jpIsWs, + parameters: [b : Nat], + result: Bool, + body: ((b =? 32) || ((b =? 10) || ((b =? 13) || (b =? 9)))) +} + +definition{name: jpIsDigit, parameters: [b : Nat], result: Bool, body: ((47 i + | Nat.succ rest => (if ((jpLen s) i + | Nat.succ rest => (if (jpIsDigit (jpAt s i)) then (jpDigitsFrom s (i + 1) rest) else i)), + axioms: [Quot.sound, propext], + recursive_argument: fuel +} + +definition{ + name: jpDigits, + parameters: [s : Bytes, i : Nat], + result: Nat, + body: (jpDigitsFrom s i ((jpLen s) + 1)), + axioms: [Quot.sound, propext] +} + +definition{ + name: jpHex, + parameters: [b : Nat], + result: Nat, + body: (if (jpIsDigit b) then (prim subtract b 48 : Nat) else (if ((96 (ctor Option.none [Nat]) + | Nat.succ rest => (let b : Nat := (jpAt s i); (if ((jpLen s) (ctor Option.none [Nat]) + | Nat.succ rest => (if (mode =? 1) then (if ((jpAt s i) =? 34) then (match (jpVStringFrom s (i + 1) ((jpLen s) + 1)) + | Option.none => (ctor Option.none [Nat]) + | Option.some k => (let c : Nat := (jpWs s k); (if ((jpAt s c) =? 58) then (match (jpV s (jpWs s (c + 1)) 0 rest) + | Option.none => (ctor Option.none [Nat]) + | Option.some e => (let n : Nat := (jpWs s e); (if ((jpAt s n) =? 44) then (jpV s (jpWs s (n + 1)) 1 rest) else (if ((jpAt s n) =? 125) then (ctor Option.some [Nat] (n + 1)) else (ctor Option.none [Nat]))))) else (ctor Option.none [Nat])))) else (ctor Option.none [Nat])) else (if (mode =? 2) then (match (jpV s i 0 rest) + | Option.none => (ctor Option.none [Nat]) + | Option.some e => (let n : Nat := (jpWs s e); (if ((jpAt s n) =? 44) then (jpV s (jpWs s (n + 1)) 2 rest) else (if ((jpAt s n) =? 93) then (ctor Option.some [Nat] (n + 1)) else (ctor Option.none [Nat]))))) else (let b : Nat := (jpAt s i); (if (b =? 34) then (jpVStringFrom s (i + 1) ((jpLen s) + 1)) else (if (b =? 123) then (let j : Nat := (jpWs s (i + 1)); (if ((jpAt s j) =? 125) then (ctor Option.some [Nat] (j + 1)) else (jpV s j 1 rest))) else (if (b =? 91) then (let j : Nat := (jpWs s (i + 1)); (if ((jpAt s j) =? 93) then (ctor Option.some [Nat] (j + 1)) else (jpV s j 2 rest))) else (if (b =? 116) then (jpLit s i 0x74727565) else (if (b =? 102) then (jpLit s i 0x66616c7365) else (if (b =? 110) then (jpLit s i 0x6e756c6c) else (jpVNumber s i))))))))))), + axioms: [Quot.sound, propext], + recursive_argument: fuel +} + +definition{ + name: jpValid, + parameters: [s : Bytes], + result: Bool, + body: (match (jpV s (jpWs s 0) 0 ((prim multiply (jpLen s) 2 : Nat) + 2)) + | Option.none => false + | Option.some e => ((jpWs s e) =? (jpLen s))), + axioms: [Quot.sound, propext] +} + +definition{ + name: jpCompactFrom, + parameters: [s : Bytes, i : Nat, start : Nat, ins : Bool, esc : Bool, acc : Bytes, fuel : Nat], + result: Bytes, + body: (match fuel + | Nat.zero => (jpCat acc (jpSpan s start (jpLen s))) + | Nat.succ rest => (if ((jpLen s) (ctor Option.none [Bytes]) + | Nat.succ rest => (let e : Nat := (sjRunEnd s i (jpLen s)); (let got : Bytes := (jpCat acc (jpSpan s i e)); (let b : Nat := (jpAt s e); (if ((jpLen s) (ctor Option.none [Bytes]) + | Option.some x => (jpDecodeFrom s (e + 2) (jpCat got x) rest)))))))))), + axioms: [Quot.sound, propext], + recursive_argument: fuel +} + +definition{ + name: jpDecode, + parameters: [s : Bytes, i : Nat], + result: (Option Bytes), + body: (jpDecodeFrom s i 0x ((jpLen s) + 1)), + axioms: [Quot.sound, propext] +} + +definition{ + name: jpHexDigit, + parameters: [n : Nat], + result: Bytes, + body: (jpSpan 0x30313233343536373839616263646566 n (n + 1)) +} + +definition{ + name: jpEsc, + parameters: [b : Nat], + result: Bytes, + body: (if (b =? 34) then 0x5c22 else (if (b =? 92) then 0x5c5c else (if (b =? 8) then 0x5c62 else (if (b =? 12) then 0x5c66 else (if (b =? 10) then 0x5c6e else (if (b =? 13) then 0x5c72 else (if (b =? 9) then 0x5c74 else (jpCat 0x5c753030 (jpCat (jpHexDigit (prim quotient b 16 0 : Nat)) (jpHexDigit (prim remainder b 16 0 : Nat))))))))))) +} + +definition{ + name: jpEncFrom, + parameters: [t : Bytes, i : Nat, start : Nat, acc : Bytes, fuel : Nat], + result: Bytes, + body: (match fuel + | Nat.zero => (jpCat acc (jpSpan t start (jpLen t))) + | Nat.succ rest => (if ((jpLen t) (ctor Option.none [JpHit]) + | Nat.succ rest => (let v : Nat := ((sjStringEnd s (i + 1)) + 2); (let e : Nat := (sjValueEnd s v); (let hit : Bool := (match (jpDecode s (i + 1)) + | Option.none => false + | Option.some k => (jpSame k key)); (if (hit && true) then (ctor Option.some [JpHit] (record JpHit {start := i, vstart := v, vend := e})) else (if ((jpAt s e) =? 44) then (jpMemberFrom s (e + 1) key rest) else (ctor Option.none [JpHit]))))))), + axioms: [Quot.sound, propext], + recursive_argument: fuel +} + +definition{ + name: jpMember, + parameters: [s : Bytes, key : Bytes], + result: (Option JpHit), + body: (if ((jpAt s 0) =? 123) then (if ((jpAt s 1) =? 125) then (ctor Option.none [JpHit]) else (jpMemberFrom s 1 key ((jpLen s) + 1))) else (ctor Option.none [JpHit])), + axioms: [Quot.sound, propext] +} + +definition{ + name: jpElementFrom, + parameters: [s : Bytes, i : Nat, n : Nat, fuel : Nat], + result: (Option JpHit), + body: (match fuel + | Nat.zero => (ctor Option.none [JpHit]) + | Nat.succ rest => (let e : Nat := (sjValueEnd s i); (if (n =? 0) then (ctor Option.some [JpHit] (record JpHit {start := i, vstart := i, vend := e})) else (if ((jpAt s e) =? 44) then (jpElementFrom s (e + 1) (prim subtract n 1 : Nat) rest) else (ctor Option.none [JpHit]))))), + axioms: [Quot.sound, propext], + recursive_argument: fuel +} + +definition{ + name: jpElement, + parameters: [s : Bytes, n : Nat], + result: (Option JpHit), + body: (if ((jpAt s 0) =? 91) then (if ((jpAt s 1) =? 93) then (ctor Option.none [JpHit]) else (jpElementFrom s 1 n ((jpLen s) + 1))) else (ctor Option.none [JpHit])), + axioms: [Quot.sound, propext] +} + +definition{ + name: jpCountFrom, + parameters: [s : Bytes, i : Nat, acc : Nat, fuel : Nat], + result: Nat, + body: (match fuel + | Nat.zero => acc + | Nat.succ rest => (let e : Nat := (sjValueEnd s i); (if ((jpAt s e) =? 44) then (jpCountFrom s (e + 1) (acc + 1) rest) else (acc + 1)))), + axioms: [Quot.sound, propext], + recursive_argument: fuel +} + +definition{ + name: jpCount, + parameters: [s : Bytes], + result: Nat, + body: (if ((jpAt s 0) =? 91) then (if ((jpAt s 1) =? 93) then 0 else (jpCountFrom s 1 0 ((jpLen s) + 1))) else 0), + axioms: [Quot.sound, propext] +} + +definition{ + name: jpCut, + parameters: [s : Bytes, a : Nat, b : Nat], + result: Bytes, + body: (if ((jpAt s b) =? 44) then (jpCat (jpSpan s 0 a) (jpSpan s (b + 1) (jpLen s))) else (if ((0 (ctor Option.none [JpTok]) + | Nat.succ rest => (if (((jpLen p) (ctor Option.none [Nat]) + | Nat.succ rest => (if ((jpLen t) (ctor Option.none [Bytes]) + | Option.some e => (ctor Option.some [Bytes] (jpSplice s (project e start) (project e start) (jpCat val 0x2c))))))), + axioms: [Quot.sound, propext] +} + +definition{ + name: jpEdit, + parameters: [s : Bytes, p : Bytes, i : Nat, op : Nat, val : Bytes, fuel : Nat], + result: (Option Bytes), + body: (match fuel + | Nat.zero => (ctor Option.none [Bytes]) + | Nat.succ rest => (if ((jpLen p) (ctor Option.none [Bytes]) + | Option.some tk => (let t : Bytes := (project tk tok); (let j : Nat := (project tk next); (let last : Bool := ((jpLen p) (if (last && (op =? 0)) then (ctor Option.some [Bytes] (jpAddMember s t val)) else (ctor Option.none [Bytes])) + | Option.some m => (if (last && true) then (if (op =? 1) then (ctor Option.some [Bytes] (jpCut s (project m start) (project m vend))) else (ctor Option.some [Bytes] (jpSplice s (project m vstart) (project m vend) val))) else (match (jpEdit (jpSpan s (project m vstart) (project m vend)) p j op val rest) + | Option.none => (ctor Option.none [Bytes]) + | Option.some c => (ctor Option.some [Bytes] (jpSplice s (project m vstart) (project m vend) c))))) else (if (b =? 91) then (let c : Nat := (jpCount s); (let n : (Option Nat) := (if ((last && (op =? 0)) && (jpSame t 0x2d)) then (ctor Option.some [Nat] c) else (jpIndex t)); (match n + | Option.none => (ctor Option.none [Bytes]) + | Option.some k => (if (last && (op =? 0)) then (jpAddElement s c k val) else (match (jpElement s k) + | Option.none => (ctor Option.none [Bytes]) + | Option.some e => (if (last && true) then (if (op =? 1) then (ctor Option.some [Bytes] (jpCut s (project e start) (project e vend))) else (ctor Option.some [Bytes] (jpSplice s (project e start) (project e vend) val))) else (match (jpEdit (jpSpan s (project e start) (project e vend)) p j op val rest) + | Option.none => (ctor Option.none [Bytes]) + | Option.some r => (ctor Option.some [Bytes] (jpSplice s (project e start) (project e vend) r))))))))) else (ctor Option.none [Bytes])))))))))), + axioms: [Quot.sound, propext], + recursive_argument: fuel +} + +definition{ + name: jpGet, + parameters: [s : Bytes, p : Bytes, i : Nat, fuel : Nat], + result: (Option Bytes), + body: (match fuel + | Nat.zero => (ctor Option.none [Bytes]) + | Nat.succ rest => (if ((jpLen p) (ctor Option.none [Bytes]) + | Option.some tk => (let t : Bytes := (project tk tok); (let j : Nat := (project tk next); (let b : Nat := (jpAt s 0); (if (b =? 123) then (match (jpMember s t) + | Option.none => (ctor Option.none [Bytes]) + | Option.some m => (jpGet (jpSpan s (project m vstart) (project m vend)) p j rest)) else (if (b =? 91) then (match (jpIndex t) + | Option.none => (ctor Option.none [Bytes]) + | Option.some k => (match (jpElement s k) + | Option.none => (ctor Option.none [Bytes]) + | Option.some e => (jpGet (jpSpan s (project e start) (project e vend)) p j rest))) else (ctor Option.none [Bytes]))))))))), + axioms: [Quot.sound, propext], + recursive_argument: fuel +} + +definition{ + name: jpNatFrom, + parameters: [s : Bytes, i : Nat, acc : Nat, fuel : Nat], + result: Nat, + body: (match fuel + | Nat.zero => acc + | Nat.succ rest => (let b : Nat := (jpAt s i); (if (jpIsDigit b) then (jpNatFrom s (i + 1) ((prim multiply acc 10 : Nat) + (prim subtract b 48 : Nat)) rest) else acc))), + axioms: [Quot.sound, propext], + recursive_argument: fuel +} + +definition{ + name: jpDecFrom, + parameters: [n : Nat, fuel : Nat], + result: Bytes, + body: (match fuel + | Nat.zero => 0x + | Nat.succ rest => (if (n i + | Nat.succ rest => (if ((jpLen d) j + | Nat.succ rest => (if (j =? 0) then 0 else (if ((jpAt d (prim subtract j 1 : Nat)) =? 48) then (jpLastNonZero d (prim subtract j 1 : Nat) rest) else j))), + axioms: [Quot.sound, propext], + recursive_argument: fuel +} + +definition{ + name: jpNumCanon, + parameters: [s : Bytes], + result: Bytes, + body: (let neg : Bool := ((jpAt s 0) =? 45); (let i : Nat := (if (neg && true) then 1 else 0); (let j : Nat := (jpDigits s i); (let ip : Bytes := (jpSpan s i j); (let hasF : Bool := ((jpAt s j) =? 46); (let k : Nat := (if (hasF && true) then (jpDigits s (j + 1)) else j); (let fp : Bytes := (if (hasF && true) then (jpSpan s (j + 1) k) else 0x); (let hasE : Bool := (((jpAt s k) =? 101) || ((jpAt s k) =? 69)); (let sgn : Nat := (jpAt s (k + 1)); (let es : Nat := (if ((sgn =? 43) || (sgn =? 45)) then (k + 2) else (k + 1)); (let ev : Nat := (if (hasE && true) then (jpNatFrom s es 0 ((jpLen s) + 1)) else 0); (let eneg : Bool := (hasE && (sgn =? 45)); (let d : Bytes := (jpCat ip fp); (let a : Nat := (jpFirstNonZero d 0 ((jpLen d) + 1)); (let z : Nat := (jpLastNonZero d (jpLen d) ((jpLen d) + 1)); (if (z false + | Nat.succ rest => (match (jpDecode s (i + 1)) + | Option.none => false + | Option.some k => (let e : Nat := (sjValueEnd s ((sjStringEnd s (i + 1)) + 2)); (if ((jpAt s e) =? 44) then (jpKeysOkFrom s (e + 1) rest) else true)))), + axioms: [Quot.sound, propext], + recursive_argument: fuel +} + +definition{ + name: jpKeysOk, + parameters: [s : Bytes], + result: Bool, + body: (if ((jpAt s 1) =? 125) then true else (jpKeysOkFrom s 1 ((jpLen s) + 1))), + axioms: [Quot.sound, propext] +} + +definition{ + name: jpBestFrom, + parameters: [s : Bytes, i : Nat, prev : (Option Bytes), best : (Option JpBest), fuel : Nat], + result: (Option JpBest), + body: (match fuel + | Nat.zero => best + | Nat.succ rest => (let v : Nat := ((sjStringEnd s (i + 1)) + 2); (let e : Nat := (sjValueEnd s v); (let k : Bytes := (match (jpDecode s (i + 1)) + | Option.none => 0x + | Option.some x => x); (let above : Bool := (match prev + | Option.none => true + | Option.some q => (jpLess q k)); (let better : Bool := (match best + | Option.none => true + | Option.some bb => (jpLess k (project bb key))); (let nb : (Option JpBest) := (if (above && better) then (ctor Option.some [JpBest] (record JpBest {key := k, bstart := v, bend := e})) else best); (if ((jpAt s e) =? 44) then (jpBestFrom s (e + 1) prev nb rest) else nb)))))))), + axioms: [Quot.sound, propext], + recursive_argument: fuel +} + +definition{ + name: jpBest, + parameters: [s : Bytes, prev : (Option Bytes)], + result: (Option JpBest), + body: (if ((jpAt s 1) =? 125) then (ctor Option.none [JpBest]) else (jpBestFrom s 1 prev (ctor Option.none [JpBest]) ((jpLen s) + 1))), + axioms: [Quot.sound, propext] +} + +definition{ + name: jpCanon, + parameters: [s : Bytes, mode : Nat, prev : (Option Bytes), acc : Bytes, n : Nat, fuel : Nat], + result: (Option Bytes), + body: (match fuel + | Nat.zero => (ctor Option.none [Bytes]) + | Nat.succ rest => (if (mode =? 1) then (match (jpBest s prev) + | Option.none => (ctor Option.some [Bytes] (jpCat acc 0x7d)) + | Option.some bb => (match (jpCanon (jpSpan s (project bb bstart) (project bb bend)) 0 (ctor Option.none [Bytes]) 0x 0 rest) + | Option.none => (ctor Option.none [Bytes]) + | Option.some cv => (jpCanon s 1 (ctor Option.some [Bytes] (project bb key)) (jpCat (jpCat acc (if (n =? 0) then 0x else 0x2c)) (jpCat (jpCat (jpEncode (project bb key)) 0x3a) cv)) (n + 1) rest))) else (if (mode =? 2) then (match (jpElement s n) + | Option.none => (ctor Option.some [Bytes] (jpCat acc 0x5d)) + | Option.some e => (match (jpCanon (jpSpan s (project e start) (project e vend)) 0 (ctor Option.none [Bytes]) 0x 0 rest) + | Option.none => (ctor Option.none [Bytes]) + | Option.some cv => (jpCanon s 2 prev (jpCat acc (jpCat (if (n =? 0) then 0x else 0x2c) cv)) (n + 1) rest))) else (let b : Nat := (jpAt s 0); (if (b =? 34) then (match (jpDecode s 1) + | Option.none => (ctor Option.none [Bytes]) + | Option.some d => (ctor Option.some [Bytes] (jpEncode d))) else (if (b =? 91) then (jpCanon s 2 prev 0x5b 0 rest) else (if (b =? 123) then (if (jpKeysOk s) then (jpCanon s 1 (ctor Option.none [Bytes]) 0x7b 0 rest) else (ctor Option.none [Bytes])) else (if ((b =? 116) || ((b =? 102) || (b =? 110))) then (ctor Option.some [Bytes] s) else (ctor Option.some [Bytes] (jpNumCanon s)))))))))), + axioms: [Quot.sound, propext], + recursive_argument: fuel +} + +definition{ + name: jpCanonical, + parameters: [s : Bytes], + result: (Option Bytes), + body: (jpCanon s 0 (ctor Option.none [Bytes]) 0x 0 ((prim multiply (jpLen s) 3 : Nat) + 3)), + axioms: [Quot.sound, propext] +} + +definition{ + name: jpEqual, + parameters: [a : Bytes, b : Bytes], + result: Bool, + body: (match (jpCanonical a) + | Option.none => false + | Option.some x => (match (jpCanonical b) + | Option.none => false + | Option.some y => (jpSame x y))), + axioms: [Quot.sound, propext] +} + +definition{ + name: jpCountKeyFrom, + parameters: [s : Bytes, i : Nat, key : Bytes, acc : Nat, fuel : Nat], + result: Nat, + body: (match fuel + | Nat.zero => acc + | Nat.succ rest => (let e : Nat := (sjValueEnd s ((sjStringEnd s (i + 1)) + 2)); (let hit : Nat := (match (jpDecode s (i + 1)) + | Option.none => 0 + | Option.some k => (if (jpSame k key) then 1 else 0)); (if ((jpAt s e) =? 44) then (jpCountKeyFrom s (e + 1) key (acc + hit) rest) else (acc + hit))))), + axioms: [Quot.sound, propext], + recursive_argument: fuel +} + +definition{ + name: jpCountKey, + parameters: [s : Bytes, key : Bytes], + result: Nat, + body: (if ((jpAt s 1) =? 125) then 0 else (jpCountKeyFrom s 1 key 0 ((jpLen s) + 1))), + axioms: [Quot.sound, propext] +} + +definition{ + name: jpValue, + parameters: [s : Bytes, key : Bytes], + result: (Option Bytes), + body: (match (jpMember s key) + | Option.none => (ctor Option.none [Bytes]) + | Option.some m => (ctor Option.some [Bytes] (jpSpan s (project m vstart) (project m vend)))), + axioms: [Quot.sound, propext] +} + +definition{ + name: jpPointer, + parameters: [v : (Option Bytes)], + result: (Option Bytes), + body: (match v + | Option.none => (ctor Option.none [Bytes]) + | Option.some x => (if ((jpAt x 0) =? 34) then (match (jpDecode x 1) + | Option.none => (ctor Option.none [Bytes]) + | Option.some d => (if (((jpLen d) =? 0) || ((jpAt d 0) =? 47)) then (ctor Option.some [Bytes] d) else (ctor Option.none [Bytes]))) else (ctor Option.none [Bytes]))), + axioms: [Quot.sound, propext] +} + +definition{ + name: jpPrefix, + parameters: [f : Bytes, p : Bytes], + result: Bool, + body: (((jpLen f) (ctor Option.none [Bytes]) + | Option.some fr => (match (jpGet doc fr 0 f) + | Option.none => (ctor Option.none [Bytes]) + | Option.some v => (if (copy && true) then (jpEdit doc path 0 0 v f) else (if (jpPrefix fr path) then (ctor Option.none [Bytes]) else (match (jpEdit doc fr 0 1 0x f) + | Option.none => (ctor Option.none [Bytes]) + | Option.some r => (jpEdit r path 0 0 v f)))))), + axioms: [Quot.sound, propext] +} + +definition{ + name: jpReplace, + parameters: [doc : Bytes, path : Bytes, val : (Option Bytes), f : Nat], + result: (Option Bytes), + body: (match val + | Option.none => (ctor Option.none [Bytes]) + | Option.some v => (match (jpGet doc path 0 f) + | Option.none => (ctor Option.none [Bytes]) + | Option.some w => (jpEdit doc path 0 2 v f))), + axioms: [Quot.sound, propext] +} + +definition{ + name: jpTest, + parameters: [doc : Bytes, path : Bytes, val : (Option Bytes), f : Nat], + result: (Option Bytes), + body: (match val + | Option.none => (ctor Option.none [Bytes]) + | Option.some v => (match (jpGet doc path 0 f) + | Option.none => (ctor Option.none [Bytes]) + | Option.some w => (if (jpEqual w v) then (ctor Option.some [Bytes] doc) else (ctor Option.none [Bytes])))), + axioms: [Quot.sound, propext] +} + +definition{ + name: jpAdd, + parameters: [doc : Bytes, path : Bytes, val : (Option Bytes), f : Nat], + result: (Option Bytes), + body: (match val + | Option.none => (ctor Option.none [Bytes]) + | Option.some v => (jpEdit doc path 0 0 v f)), + axioms: [Quot.sound, propext] +} + +definition{ + name: jpOp, + parameters: [doc : Bytes, o : Bytes, op : Bytes, path : Bytes, f : Nat], + result: (Option Bytes), + body: (let val : (Option Bytes) := (jpValue o 0x76616c7565); (if (jpSame op 0x616464) then (jpAdd doc path val f) else (if (jpSame op 0x72656d6f7665) then (jpEdit doc path 0 1 0x f) else (if (jpSame op 0x7265706c616365) then (jpReplace doc path val f) else (if (jpSame op 0x6d6f7665) then (jpMoveCopy doc o path false f) else (if (jpSame op 0x636f7079) then (jpMoveCopy doc o path true f) else (if (jpSame op 0x74657374) then (jpTest doc path val f) else (ctor Option.none [Bytes])))))))), + axioms: [Quot.sound, propext] +} + +definition{ + name: jpApply, + parameters: [doc : Bytes, o : Bytes], + result: (Option Bytes), + body: (let f : Nat := (((jpLen doc) + (jpLen o)) + 2); (if (((jpAt o 0) =? 123) && (jpOnce o)) then (match (jpValue o 0x6f70) + | Option.none => (ctor Option.none [Bytes]) + | Option.some opv => (match (jpPointer (jpValue o 0x70617468)) + | Option.none => (ctor Option.none [Bytes]) + | Option.some path => (match (if ((jpAt opv 0) =? 34) then (jpDecode opv 1) else (ctor Option.none [Bytes])) + | Option.none => (ctor Option.none [Bytes]) + | Option.some op => (jpOp doc o op path f)))) else (ctor Option.none [Bytes]))), + axioms: [Quot.sound, propext] +} + +definition{ + name: jpPatchFrom, + parameters: [doc : Bytes, p : Bytes, n : Nat, fuel : Nat], + result: (Option Bytes), + body: (match fuel + | Nat.zero => (ctor Option.none [Bytes]) + | Nat.succ rest => (match (jpElement p n) + | Option.none => (ctor Option.some [Bytes] doc) + | Option.some e => (match (jpApply doc (jpSpan p (project e start) (project e vend))) + | Option.none => (ctor Option.none [Bytes]) + | Option.some d => (jpPatchFrom d p (n + 1) rest)))), + axioms: [Quot.sound, propext], + recursive_argument: fuel +} + +definition{ + name: jpRun, + parameters: [doc : Bytes, p : Bytes], + result: (Option Bytes), + body: (if ((jpAt p 0) =? 91) then (jpPatchFrom doc p 0 ((jpLen p) + 1)) else (ctor Option.none [Bytes])), + axioms: [Quot.sound, propext] +} + +definition{ + name: jpPatch, + parameters: [doc : Bytes, patch : Bytes], + result: (Option Bytes), + body: (if ((jpValid doc) && (jpValid patch)) then (jpRun (jpCompact doc) (jpCompact patch)) else (ctor Option.none [Bytes])), + axioms: [Quot.sound, propext] +} + +structure{ + name: JcDouble, + type_parameters: [], + parameters: [], + fields: [{name: neg, type: Bool}, {name: sig, type: Nat}, {name: exb, type: Nat}] +} + +structure{ + name: JcDigits, + type_parameters: [], + parameters: [], + fields: [{name: digits, type: Nat}, {name: count, type: Nat}, {name: point, type: Nat}] +} + +structure{ + name: JcDiv, + type_parameters: [], + parameters: [], + fields: [{name: quo, type: Nat}, {name: rem, type: Bytes}] +} + +structure{ + name: JcKey, + type_parameters: [], + parameters: [], + fields: [ + {name: key, type: Bytes}, + {name: order, type: Bytes}, + {name: kstart, type: Nat}, + {name: kend, type: Nat} + ] +} + +definition{ + name: jcPowFrom, + parameters: [base : Nat, k : Nat, acc : Nat, fuel : Nat], + result: Nat, + body: (match fuel + | Nat.zero => acc + | Nat.succ rest => (if (k =? 0) then acc else (jcPowFrom base (prim subtract k 1 : Nat) (prim multiply acc base : Nat) rest))), + recursive_argument: fuel +} + +definition{ + name: jcPow, + parameters: [base : Nat, k : Nat], + result: Nat, + body: (jcPowFrom base k 1 (k + 1)) +} + +definition{ + name: jcDigitCountFrom, + parameters: [n : Nat, acc : Nat, fuel : Nat], + result: Nat, + body: (match fuel + | Nat.zero => acc + | Nat.succ rest => (if (n (jpSpan a 0 j) + | Nat.succ rest => (if (j =? 0) then 0x else (if ((jpAt a (prim subtract j 1 : Nat)) =? 0) then (jbNormFrom a (prim subtract j 1 : Nat) rest) else (jpSpan a 0 j)))), + axioms: [Quot.sound, propext], + recursive_argument: fuel +} + +definition{ + name: jbNorm, + parameters: [a : Bytes], + result: Bytes, + body: (jbNormFrom a (jpLen a) ((jpLen a) + 1)), + axioms: [Quot.sound, propext] +} + +definition{ + name: jbFromNatFrom, + parameters: [n : Nat, acc : Bytes, fuel : Nat], + result: Bytes, + body: (match fuel + | Nat.zero => acc + | Nat.succ rest => (if (n =? 0) then acc else (jbFromNatFrom (prim quotient n 256 0 : Nat) (jpCat acc (jpByte (prim remainder n 256 0 : Nat))) rest))), + recursive_argument: fuel +} + +definition{name: jbFromNat, parameters: [n : Nat], result: Bytes, body: (jbFromNatFrom n 0x 9)} + +definition{ + name: jbMulFrom, + parameters: [a : Bytes, i : Nat, m : Nat, carry : Nat, acc : Bytes, fuel : Nat], + result: Bytes, + body: (match fuel + | Nat.zero => acc + | Nat.succ rest => (if ((jpLen a) a + | Nat.succ rest => (if (k =? 0) then a else (jbPowMulFrom (jbMul a base 0) base (prim subtract k 1 : Nat) rest))), + axioms: [Quot.sound, propext], + recursive_argument: fuel +} + +definition{ + name: jbPowMul, + parameters: [a : Bytes, base : Nat, k : Nat], + result: Bytes, + body: (jbPowMulFrom a base k (k + 1)), + axioms: [Quot.sound, propext] +} + +definition{ + name: jbCmpFrom, + parameters: [a : Bytes, b : Bytes, i : Nat, fuel : Nat], + result: Nat, + body: (match fuel + | Nat.zero => 1 + | Nat.succ rest => (if (i =? 0) then 1 else (let x : Nat := (jpAt a (prim subtract i 1 : Nat)); (let y : Nat := (jpAt b (prim subtract i 1 : Nat)); (if (x acc + | Nat.succ rest => (if ((jpLen a) acc + | Nat.succ rest => (if (i =? 0) then acc else (let v : Nat := ((prim multiply c 256 : Nat) + (jpAt a (prim subtract i 1 : Nat))); (jbHalfFrom a (prim subtract i 1 : Nat) (prim remainder v 2 0 : Nat) (jpCat (jpByte (prim quotient v 2 0 : Nat)) acc) rest)))), + axioms: [Quot.sound, propext], + recursive_argument: fuel +} + +definition{ + name: jbHalf, + parameters: [a : Bytes], + result: Bytes, + body: (jbNorm (jbHalfFrom a (jpLen a) 0 0x ((jpLen a) + 1))), + axioms: [Quot.sound, propext] +} + +definition{ + name: jbTopBits, + parameters: [t : Nat, n : Nat, fuel : Nat], + result: Nat, + body: (match fuel + | Nat.zero => n + | Nat.succ rest => (if (t =? 0) then n else (jbTopBits (prim quotient t 2 0 : Nat) (n + 1) rest))), + recursive_argument: fuel +} + +definition{ + name: jbBits, + parameters: [a : Bytes], + result: Nat, + body: (if ((jpLen a) =? 0) then 0 else ((prim multiply (prim subtract (jpLen a) 1 : Nat) 8 : Nat) + (jbTopBits (jpAt a (prim subtract (jpLen a) 1 : Nat)) 0 9))), + axioms: [Quot.sound, propext] +} + +definition{ + name: jbDivFrom, + parameters: [r : Bytes, t : Bytes, i : Nat, q : Nat, fuel : Nat], + result: JcDiv, + body: (match fuel + | Nat.zero => (record JcDiv {quo := q, rem := r}) + | Nat.succ rest => (if (i =? 0) then (record JcDiv {quo := q, rem := r}) else (if ((jbCmp r t) =? 0) then (jbDivFrom r (jbHalf t) (prim subtract i 1 : Nat) q rest) else (jbDivFrom (jbSub r t) (jbHalf t) (prim subtract i 1 : Nat) (q + (jcPow 2 (prim subtract i 1 : Nat))) rest)))), + axioms: [Quot.sound, propext], + recursive_argument: fuel +} + +definition{ + name: jbDiv, + parameters: [n : Bytes, d : Bytes], + result: JcDiv, + body: (let bn : Nat := (jbBits n); (let bd : Nat := (jbBits d); (if (bn eb + | Nat.succ rest => (let q : Nat := (project (jbDiv (jcScaleNum num eb) (jcScaleDen den eb)) quo); (if ((jcPow 2 53) acc + | Nat.succ rest => (if ((jpLen s) false + | Option.some x => (((project x sig) =? m) && ((project x exb) =? eb))) +} + +definition{ + name: jcPointUp, + parameters: [num : Bytes, t : Bytes, nb : Nat, fuel : Nat], + result: Nat, + body: (match fuel + | Nat.zero => nb + | Nat.succ rest => (if ((jbCmp num t) =? 0) then nb else (jcPointUp num (jbMul t 10 0) (nb + 1) rest))), + axioms: [Quot.sound, propext], + recursive_argument: fuel +} + +definition{ + name: jcPointDown, + parameters: [t : Bytes, den : Bytes, nb : Nat, fuel : Nat], + result: Nat, + body: (match fuel + | Nat.zero => nb + | Nat.succ rest => (let t10 : Bytes := (jbMul t 10 0); (if ((jbCmp t10 den) =? 0) then (jcPointDown t10 den (prim subtract nb 1 : Nat) rest) else nb))), + axioms: [Quot.sound, propext], + recursive_argument: fuel +} + +definition{ + name: jcTryFrom, + parameters: [num : Bytes, den : Bytes, m : Nat, eb : Nat, nb : Nat, k : Nat, fuel : Nat], + result: JcDigits, + body: (match fuel + | Nat.zero => (record JcDigits {digits := 0, count := 0, point := nb}) + | Nat.succ rest => (let a : Bytes := (if (nb acc + | Nat.succ rest => (if (n =? 0) then acc else (jcZeros (prim subtract n 1 : Nat) (jpCat acc 0x30) rest))), + recursive_argument: fuel +} + +definition{ + name: jcLayout, + parameters: [g : JcDigits], + result: Bytes, + body: (let d : Bytes := (jpDec (project g digits)); (let k : Nat := (project g count); (let nb : Nat := (project g point); (if (((k + 400) acc + | Nat.succ rest => (if (k n + | Nat.succ rest => (if (k acc + | Nat.succ rest => (let b : Nat := (jpAt s i); (if ((b (ctor Option.none [Bytes]) + | Option.some x => (ctor Option.some [Bytes] (jcSerialize x))), + axioms: [Quot.sound, propext] +} + +definition{ + name: jcUtf16From, + parameters: [t : Bytes, i : Nat, acc : Bytes, fuel : Nat], + result: Bytes, + body: (match fuel + | Nat.zero => acc + | Nat.succ rest => (if ((jpLen t) best + | Nat.succ rest => (let v : Nat := ((sjStringEnd s (i + 1)) + 2); (let e : Nat := (sjValueEnd s v); (let k : Bytes := (match (jpDecode s (i + 1)) + | Option.none => 0x + | Option.some x => x); (let o : Bytes := (jcUtf16 k); (let above : Bool := (match prev + | Option.none => true + | Option.some q => (jpLess q o)); (let better : Bool := (match best + | Option.none => true + | Option.some bb => (jpLess o (project bb order))); (let nb : (Option JcKey) := (if (above && better) then (ctor Option.some [JcKey] (record JcKey {key := k, order := o, kstart := v, kend := e})) else best); (if ((jpAt s e) =? 44) then (jcBestFrom s (e + 1) prev nb rest) else nb))))))))), + axioms: [Quot.sound, propext], + recursive_argument: fuel +} + +definition{ + name: jcBest, + parameters: [s : Bytes, prev : (Option Bytes)], + result: (Option JcKey), + body: (if ((jpAt s 1) =? 125) then (ctor Option.none [JcKey]) else (jcBestFrom s 1 prev (ctor Option.none [JcKey]) ((jpLen s) + 1))), + axioms: [Quot.sound, propext] +} + +definition{ + name: jcDuplicateFrom, + parameters: [s : Bytes, prev : (Option Bytes), fuel : Nat], + result: Bool, + body: (match fuel + | Nat.zero => false + | Nat.succ rest => (match (jcBest s prev) + | Option.none => false + | Option.some bb => (if ((jpCountKey s (project bb key)) (ctor Option.none [Bytes]) + | Nat.succ rest => (if (mode =? 1) then (match (jcBest s prev) + | Option.none => (ctor Option.some [Bytes] (jpCat acc 0x7d)) + | Option.some bb => (match (jcCanon (jpSpan s (project bb kstart) (project bb kend)) 0 (ctor Option.none [Bytes]) 0x 0 rest) + | Option.none => (ctor Option.none [Bytes]) + | Option.some cv => (jcCanon s 1 (ctor Option.some [Bytes] (project bb order)) (jpCat (jpCat acc (if (n =? 0) then 0x else 0x2c)) (jpCat (jpCat (jpEncode (project bb key)) 0x3a) cv)) (n + 1) rest))) else (if (mode =? 2) then (match (jpElement s n) + | Option.none => (ctor Option.some [Bytes] (jpCat acc 0x5d)) + | Option.some e => (match (jcCanon (jpSpan s (project e start) (project e vend)) 0 (ctor Option.none [Bytes]) 0x 0 rest) + | Option.none => (ctor Option.none [Bytes]) + | Option.some cv => (jcCanon s 2 prev (jpCat acc (jpCat (if (n =? 0) then 0x else 0x2c) cv)) (n + 1) rest))) else (let b : Nat := (jpAt s 0); (if (b =? 34) then (match (jpDecode s 1) + | Option.none => (ctor Option.none [Bytes]) + | Option.some d => (ctor Option.some [Bytes] (jpEncode d))) else (if (b =? 91) then (jcCanon s 2 prev 0x5b 0 rest) else (if (b =? 123) then (if (jpKeysOk s) then (if (jcDuplicateFrom s (ctor Option.none [Bytes]) ((jpLen s) + 1)) then (ctor Option.none [Bytes]) else (jcCanon s 1 (ctor Option.none [Bytes]) 0x7b 0 rest)) else (ctor Option.none [Bytes])) else (if ((b =? 116) || ((b =? 102) || (b =? 110))) then (ctor Option.some [Bytes] s) else (jcNumber s))))))))), + axioms: [Quot.sound, propext], + recursive_argument: fuel +} + +definition{ + name: jcCanonicalize, + parameters: [s : Bytes], + result: (Option Bytes), + body: (if (jpValid s) then (let c : Bytes := (jpCompact s); (jcCanon c 0 (ctor Option.none [Bytes]) 0x 0 ((prim multiply (jpLen c) 3 : Nat) + 3))) else (ctor Option.none [Bytes])), + axioms: [Quot.sound, propext] +} + +definition{name: shaMask, parameters: [], result: UInt64, body: (4294967295 : UInt64)} + +definition{ + name: shaAdd, + parameters: [a : UInt64, b : UInt64], + result: UInt64, + body: (match (prim checked_add a b : (Option UInt64)) + | Option.none => (0 : UInt64) + | Option.some t => (prim bit_and t (shaMask) : UInt64)), + axioms: [Quot.sound, propext] +} + +definition{ + name: shaShr, + parameters: [x : UInt64, n : UInt32], + result: UInt64, + body: (match (prim shift_right x n : (Option UInt64)) + | Option.none => (0 : UInt64) + | Option.some r => r), + axioms: [Quot.sound, propext] +} + +definition{ + name: shaShl, + parameters: [x : UInt64, n : UInt32], + result: UInt64, + body: (match (prim shift_left x n : (Option UInt64)) + | Option.none => (0 : UInt64) + | Option.some r => (prim bit_and r (shaMask) : UInt64)), + axioms: [Quot.sound, propext] +} + +definition{ + name: shaRotr, + parameters: [x : UInt64, n : UInt32, m : UInt32], + result: UInt64, + body: (prim bit_xor (shaShr x n) (shaShl x m) : UInt64), + axioms: [Quot.sound, propext] +} + +definition{ + name: shaByteWord, + parameters: [s : Bytes, i : Nat], + result: UInt64, + body: (match (Foundation.Bytes::byteAt s i) + | Option.none => (0 : UInt64) + | Option.some b => (prim bit_or (prim bit_or (prim bit_or (prim bit_or (prim bit_or (prim bit_or (prim bit_or (prim bit_or (0 : UInt64) (match (prim equal (prim bit_and b (1 : UInt8) : UInt8) (1 : UInt8) : Bool) + | Bool.false => (0 : UInt64) + | Bool.true => (1 : UInt64)) : UInt64) (match (prim equal (prim bit_and b (2 : UInt8) : UInt8) (2 : UInt8) : Bool) + | Bool.false => (0 : UInt64) + | Bool.true => (2 : UInt64)) : UInt64) (match (prim equal (prim bit_and b (4 : UInt8) : UInt8) (4 : UInt8) : Bool) + | Bool.false => (0 : UInt64) + | Bool.true => (4 : UInt64)) : UInt64) (match (prim equal (prim bit_and b (8 : UInt8) : UInt8) (8 : UInt8) : Bool) + | Bool.false => (0 : UInt64) + | Bool.true => (8 : UInt64)) : UInt64) (match (prim equal (prim bit_and b (16 : UInt8) : UInt8) (16 : UInt8) : Bool) + | Bool.false => (0 : UInt64) + | Bool.true => (16 : UInt64)) : UInt64) (match (prim equal (prim bit_and b (32 : UInt8) : UInt8) (32 : UInt8) : Bool) + | Bool.false => (0 : UInt64) + | Bool.true => (32 : UInt64)) : UInt64) (match (prim equal (prim bit_and b (64 : UInt8) : UInt8) (64 : UInt8) : Bool) + | Bool.false => (0 : UInt64) + | Bool.true => (64 : UInt64)) : UInt64) (match (prim equal (prim bit_and b (128 : UInt8) : UInt8) (128 : UInt8) : Bool) + | Bool.false => (0 : UInt64) + | Bool.true => (128 : UInt64)) : UInt64)), + axioms: [Quot.sound, propext] +} + +definition{ + name: shaWordAt, + parameters: [s : Bytes, i : Nat], + result: UInt64, + body: (prim bit_xor (prim bit_xor (shaShl (shaByteWord s i) (24 : UInt32)) (shaShl (shaByteWord s (i + 1)) (16 : UInt32)) : UInt64) (prim bit_xor (shaShl (shaByteWord s (i + 2)) (8 : UInt32)) (shaByteWord s (i + 3)) : UInt64) : UInt64), + axioms: [Quot.sound, propext] +} + +definition{ + name: shaOctets, + parameters: [], + result: Bytes, + body: 0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff +} + +definition{ + name: shaOctet, + parameters: [b : Nat], + result: Bytes, + body: (match (Foundation.Bytes::sliceBytes (shaOctets) b 1) + | Option.none => 0x + | Option.some o => o) +} + +definition{ + name: shaNibble, + parameters: [n : Nat], + result: Bytes, + body: (match (Foundation.Bytes::sliceBytes 0x30313233343536373839616263646566 n 1) + | Option.none => 0x + | Option.some o => o) +} + +definition{ + name: shaOctetNat, + parameters: [value : UInt8], + result: Nat, + body: ((((((((0 + (match (prim equal (prim bit_and value (1 : UInt8) : UInt8) (1 : UInt8) : Bool) + | Bool.false => 0 + | Bool.true => 1)) + (match (prim equal (prim bit_and value (2 : UInt8) : UInt8) (2 : UInt8) : Bool) + | Bool.false => 0 + | Bool.true => 2)) + (match (prim equal (prim bit_and value (4 : UInt8) : UInt8) (4 : UInt8) : Bool) + | Bool.false => 0 + | Bool.true => 4)) + (match (prim equal (prim bit_and value (8 : UInt8) : UInt8) (8 : UInt8) : Bool) + | Bool.false => 0 + | Bool.true => 8)) + (match (prim equal (prim bit_and value (16 : UInt8) : UInt8) (16 : UInt8) : Bool) + | Bool.false => 0 + | Bool.true => 16)) + (match (prim equal (prim bit_and value (32 : UInt8) : UInt8) (32 : UInt8) : Bool) + | Bool.false => 0 + | Bool.true => 32)) + (match (prim equal (prim bit_and value (64 : UInt8) : UInt8) (64 : UInt8) : Bool) + | Bool.false => 0 + | Bool.true => 64)) + (match (prim equal (prim bit_and value (128 : UInt8) : UInt8) (128 : UInt8) : Bool) + | Bool.false => 0 + | Bool.true => 128)), + axioms: [Quot.sound, propext] +} + +definition{ + name: shaLow, + parameters: [x : UInt64], + result: Nat, + body: ((((((((0 + (match (prim equal (prim bit_and x (1 : UInt64) : UInt64) (1 : UInt64) : Bool) + | Bool.false => 0 + | Bool.true => 1)) + (match (prim equal (prim bit_and x (2 : UInt64) : UInt64) (2 : UInt64) : Bool) + | Bool.false => 0 + | Bool.true => 2)) + (match (prim equal (prim bit_and x (4 : UInt64) : UInt64) (4 : UInt64) : Bool) + | Bool.false => 0 + | Bool.true => 4)) + (match (prim equal (prim bit_and x (8 : UInt64) : UInt64) (8 : UInt64) : Bool) + | Bool.false => 0 + | Bool.true => 8)) + (match (prim equal (prim bit_and x (16 : UInt64) : UInt64) (16 : UInt64) : Bool) + | Bool.false => 0 + | Bool.true => 16)) + (match (prim equal (prim bit_and x (32 : UInt64) : UInt64) (32 : UInt64) : Bool) + | Bool.false => 0 + | Bool.true => 32)) + (match (prim equal (prim bit_and x (64 : UInt64) : UInt64) (64 : UInt64) : Bool) + | Bool.false => 0 + | Bool.true => 64)) + (match (prim equal (prim bit_and x (128 : UInt64) : UInt64) (128 : UInt64) : Bool) + | Bool.false => 0 + | Bool.true => 128)), + axioms: [Quot.sound, propext] +} + +definition{ + name: shaWordBytes, + parameters: [x : UInt64], + result: Bytes, + body: (Foundation.Bytes::appendBytes (Foundation.Bytes::appendBytes (shaOctet (shaLow (shaShr x (24 : UInt32)))) (shaOctet (shaLow (shaShr x (16 : UInt32))))) (Foundation.Bytes::appendBytes (shaOctet (shaLow (shaShr x (8 : UInt32)))) (shaOctet (shaLow x)))), + axioms: [Quot.sound, propext] +} + +definition{ + name: shaNatBe, + parameters: [x : Nat, width : Nat, acc : Bytes], + result: Bytes, + body: (match width + | Nat.zero => acc + | Nat.succ rest => (shaNatBe (prim quotient x 256 0 : Nat) rest (Foundation.Bytes::appendBytes (shaOctet (prim remainder x 256 0 : Nat)) acc))), + recursive_argument: width +} + +definition{ + name: shaK, + parameters: [], + result: Bytes, + body: 0x428a2f9871374491b5c0fbcfe9b5dba53956c25b59f111f1923f82a4ab1c5ed5d807aa9812835b01243185be550c7dc372be5d7480deb1fe9bdc06a7c19bf174e49b69c1efbe47860fc19dc6240ca1cc2de92c6f4a7484aa5cb0a9dc76f988da983e5152a831c66db00327c8bf597fc7c6e00bf3d5a7914706ca63511429296727b70a852e1b21384d2c6dfc53380d13650a7354766a0abb81c2c92e92722c85a2bfe8a1a81a664bc24b8b70c76c51a3d192e819d6990624f40e3585106aa07019a4c1161e376c082748774c34b0bcb5391c0cb34ed8aa4a5b9cca4f682e6ff3748f82ee78a5636f84c878148cc7020890befffaa4506cebbef9a3f7c67178f2 +} + +definition{ + name: shaZeros, + parameters: [n : Nat, acc : Bytes], + result: Bytes, + body: (match n + | Nat.zero => acc + | Nat.succ rest => (shaZeros rest (Foundation.Bytes::appendBytes acc 0x00))), + recursive_argument: n +} + +definition{ + name: shaPadded, + parameters: [m : Bytes], + result: Bytes, + body: (let n : Nat := (Foundation.Bytes::byteLength m); (let r : Nat := (prim remainder (n + 9) 64 0 : Nat); (let k : Nat := (if (r =? 0) then 0 else (prim subtract 64 r : Nat)); (Foundation.Bytes::appendBytes (Foundation.Bytes::appendBytes (Foundation.Bytes::appendBytes m 0x80) (shaZeros k 0x)) (shaNatBe (prim multiply n 8 : Nat) 8 0x))))) +} + +definition{ + name: shaSchedule, + parameters: [block : Bytes, t : Nat, w : Bytes, fuel : Nat], + result: Bytes, + body: (match fuel + | Nat.zero => w + | Nat.succ rest => (if (63 0x + | Nat.succ rest => (if (63 0x + | Nat.succ rest => (if (7 state + | Nat.succ rest => (match (Foundation.Bytes::sliceBytes m i 64) + | Option.none => state + | Option.some block => (let w : Bytes := (shaSchedule block 0 0x 64); (let out : Bytes := (shaRounds w 0 (shaWordAt state 0) (shaWordAt state 4) (shaWordAt state 8) (shaWordAt state 12) (shaWordAt state 16) (shaWordAt state 20) (shaWordAt state 24) (shaWordAt state 28) 65); (shaBlocks m (i + 64) (shaMix state out 0 8) rest))))), + axioms: [Quot.sound, propext], + recursive_argument: fuel +} + +definition{ + name: sha256, + parameters: [m : Bytes], + result: Bytes, + body: (let p : Bytes := (shaPadded m); (shaBlocks p 0 0x6a09e667bb67ae853c6ef372a54ff53a510e527f9b05688c1f83d9ab5be0cd19 ((prim quotient (Foundation.Bytes::byteLength p) 64 0 : Nat) + 1))), + axioms: [Quot.sound, propext] +} + +definition{ + name: shaHexFrom, + parameters: [dg : Bytes, i : Nat, n : Nat, acc : Bytes], + result: Bytes, + body: (match n + | Nat.zero => acc + | Nat.succ rest => (let b : Nat := (match (Foundation.Bytes::byteAt dg i) + | Option.none => 0 + | Option.some o => (shaOctetNat o)); (shaHexFrom dg (i + 1) rest (Foundation.Bytes::appendBytes acc (Foundation.Bytes::appendBytes (shaNibble (prim quotient b 16 0 : Nat)) (shaNibble (prim remainder b 16 0 : Nat))))))), + axioms: [Quot.sound, propext], + recursive_argument: n +} + +definition{ + name: sha256Hex, + parameters: [m : Bytes], + result: Bytes, + body: (let dg : Bytes := (sha256 m); (shaHexFrom dg 0 (Foundation.Bytes::byteLength dg) 0x)), + axioms: [Quot.sound, propext] +} + +definition{ + name: snEolFrom, + parameters: [s : Bytes, i : Nat, fuel : Nat], + result: Nat, + body: (match fuel + | Nat.zero => (jpLen s) + | Nat.succ rest => (if ((jpLen s) acc + | Nat.succ rest => (if (k =? 0) then acc else (snUnhexFrom s (i + 2) (prim subtract k 1 : Nat) (jpCat acc (jpByte ((prim multiply (jpHex (jpAt s i)) 16 : Nat) + (jpHex (jpAt s (i + 1)))))) rest))), + axioms: [Quot.sound, propext], + recursive_argument: fuel +} + +definition{ + name: snCanonical, + parameters: [p : Bytes], + result: Bytes, + body: (match (jcCanonicalize p) | Option.none => 0x6e6f7420492d4a534f4e | Option.some c => c), + axioms: [Quot.sound, propext] +} + +definition{ + name: snAddress, + parameters: [p : Bytes], + result: Bytes, + body: (match (jcCanonicalize p) + | Option.none => 0x6e6f7420492d4a534f4e + | Option.some c => (jpCat 0x7368613235363a (sha256Hex c))), + axioms: [Quot.sound, propext] +} + +definition{ + name: snApply, + parameters: [p : Bytes], + result: Bytes, + body: (let a : Bytes := (jpCompact p); (match (jpElement a 0) + | Option.none => 0x696e76616c6964 + | Option.some d => (match (jpElement a 1) + | Option.none => 0x696e76616c6964 + | Option.some q => (match (jpPatch (jpSpan a (project d vstart) (project d vend)) (jpSpan a (project q vstart) (project q vend))) + | Option.none => 0x74686520706174636820646f6573206e6f74206170706c79 + | Option.some r => (snCanonical r))))), + axioms: [Quot.sound, propext] +} + +definition{ + name: snDigest, + parameters: [p : Bytes], + result: Bytes, + body: (let e : Nat := (snEol p 0); (if (jpSame (jpSpan p 0 6) 0x4c656e203d20) then (let n : Nat := (jpNatFrom p 6 0 7); (if (jpSame (jpSpan p (e + 1) (e + 7)) 0x4d7367203d20) then (jpCat 0x4d44203d20 (sha256Hex (snUnhexFrom p (e + 7) (prim quotient n 8 0 : Nat) 0x ((prim quotient n 8 0 : Nat) + 1)))) else 0x696e76616c6964)) else 0x696e76616c6964)), + axioms: [Quot.sound, propext] +} + +definition{ + name: prismSnapshotDispatch, + parameters: [s : Bytes], + result: Bytes, + body: (if (2048 (ctor Option.none [Bytes]) + | Option.some m => (ctor Option.some [Bytes] (GenPatch::jpSpan el (project m vstart) (project m vend)))), + axioms: [Quot.sound, propext] +} + +definition{ + name: vgApplyOne, + parameters: [el : Bytes, acc : Bytes], + result: Bytes, + body: (match (vgMember el 0x646f63) + | Option.none => acc + | Option.some d => (match (vgMember el 0x7061746368) + | Option.none => acc + | Option.some q => (let req : Bytes := (GenPatch::jpCat 0x6170706c790a (GenPatch::jpCat 0x5b (GenPatch::jpCat d (GenPatch::jpCat 0x2c (GenPatch::jpCat q 0x5d))))); (match (vgMember el 0x6578706563746564) + | Option.some x => (match (GenJcs::jcCanonicalize x) + | Option.none => acc + | Option.some c => (vgJoin acc (vgPair req c))) + | Option.none => (match (vgMember el 0x6572726f72) + | Option.none => acc + | Option.some y => (vgJoin acc (vgPair req 0x74686520706174636820646f6573206e6f74206170706c79))))))), + axioms: [Quot.sound, propext] +} + +definition{ + name: vgApplyFrom, + parameters: [cases : Bytes, n : Nat, acc : Bytes, fuel : Nat], + result: Bytes, + body: (match fuel + | Nat.zero => acc + | Nat.succ rest => (match (GenPatch::jpElement cases n) + | Option.none => acc + | Option.some h => (vgApplyFrom cases (n + 1) (vgApplyOne (GenPatch::jpSpan cases (project h vstart) (project h vend)) acc) rest))), + axioms: [Quot.sound, propext], + recursive_argument: fuel +} + +definition{ + name: vgJcsFrom, + parameters: [s : Bytes, header : Nat, acc : Bytes, fuel : Nat], + result: Bytes, + body: (match fuel + | Nat.zero => acc + | Nat.succ rest => (if ((Foundation.Tar::byteOr s header) =? 0) then acc else (let size : Nat := (Foundation.Tar::entrySize s header); (let nm : Bytes := (Foundation.Tar::entryName s header); (let next : Nat := ((header + 512) + (Foundation.Tar::padded size)); (let k : Nat := (GenAddr::adFind nm 0x2f696e7075742f 0); (if ((GenPatch::jpLen nm) (vgJcsFrom s next acc rest) + | Option.some o => (let i : Bytes := (GenPatch::jpSpan s (header + 512) ((header + 512) + size)); (vgJcsFrom s next (vgJoin (vgJoin acc (vgPair (GenPatch::jpCat 0x63616e6f6e6963616c0a i) o)) (vgPair (GenPatch::jpCat 0x616464726573730a i) (GenPatch::jpCat 0x7368613235363a (Sha256::sha256Hex o)))) rest))))))))))), + axioms: [Quot.sound, propext], + recursive_argument: fuel +} + +definition{ + name: vgLineEndFrom, + parameters: [s : Bytes, i : Nat, fuel : Nat], + result: Nat, + body: (match fuel + | Nat.zero => i + | Nat.succ rest => (let b : Nat := (GenPatch::jpAt s i); (if ((b =? 13) || ((b =? 10) || ((GenPatch::jpLen s) acc + | Nat.succ rest => (let p : Nat := (GenAddr::adFind s 0x4c656e203d20 i); (if ((GenPatch::jpLen s) (ctor Option.none [Bytes]) + | Option.some t => (match (Foundation.Tar::find archive 0x6170702f73706563732f6f7261636c652f6e6973742d636176702d7368613235362f53484132353653686f72744d73672e727370) + | Option.none => (ctor Option.none [Bytes]) + | Option.some r => (let cases : Bytes := (GenPatch::jpCompact t); (let a : Bytes := (vgApplyFrom cases 0 0x ((GenPatch::jpCount cases) + 1)); (let j : Bytes := (vgJcsFrom archive 0 a ((prim quotient (GenPatch::jpLen archive) 512 0 : Nat) + 1)); (let x : Bytes := (vgShaFrom r 0 j ((prim quotient (GenPatch::jpLen r) 8 0 : Nat) + 1)); (ctor Option.some [Bytes] (GenPatch::jpCat 0x7b226e616d65223a22736e617073686f74222c22636f6d6d656e74223a2254686520616363657074616e636520766563746f7273206f662074686520736e617073686f7420677565737420286170702f7372632f507269736d536e617073686f742e6c65782e746578292c207772697474656e2066726f6d20746865206f7261636c657320756e646572206170702f73706563732f6f7261636c652062792074686520736e617073686f74766563746f72732073746570206f662067656e657261746f72732f736e617073686f742f73746570732e6a736f6e2c207768696368207361797320776861742065616368206f6e652069732e222c226578616d706c6573223a5b0a (GenPatch::jpCat x 0x0a5d7d0a))))))))), + axioms: [Quot.sound, propext] +} +\end{semanticmodule} +\end{lexlean} diff --git a/generators/snapshot/src/Generators.lex.tex b/generators/snapshot/src/Generators.lex.tex index 88c8174c..91ceafe1 100644 --- a/generators/snapshot/src/Generators.lex.tex +++ b/generators/snapshot/src/Generators.lex.tex @@ -6,6 +6,7 @@ \importmodule{GenPatch} \importmodule{GenJcs} \importmodule{GenAddr} +\importmodule{GenVec} \importmodule{Foundation.Tar} \importmodule{Foundation.View.Text.V1.Model} \importmodule{Foundation.View.Text.V3.Model} @@ -63,6 +64,16 @@ body: (Foundation.Bytes::appendBytes 0x726566757365643a20 reasons) } +definition{ + name: dispatchMore, + parameters: [name : Bytes, archive : Bytes], + result: Bytes, + body: (if (Foundation.Tar::sameBytes name 0x73686173686f7274) then (let r : GenJcs::JcReport := (GenAddr::adShort (sliceOr archive 512 (Foundation.Tar::entrySize archive 0))); (if ((Foundation.Bytes::byteLength (project r failed)) =? 0) then (written (project r passed)) else (refused (project r failed)))) else (if (Foundation.Tar::sameBytes name 0x7368616d6f6e7465) then (let r : GenJcs::JcReport := (GenAddr::adMonte (sliceOr archive 512 (Foundation.Tar::entrySize archive 0))); (if ((Foundation.Bytes::byteLength (project r failed)) =? 0) then (written (project r passed)) else (refused (project r failed)))) else (if (Foundation.Tar::sameBytes name 0x6c6f636b636865636b) then (let r : GenJcs::JcReport := (GenAddr::adLock archive); (if ((Foundation.Bytes::byteLength (project r failed)) =? 0) then (written (project r passed)) else (refused (project r failed)))) else (if (Foundation.Tar::sameBytes name 0x736e617073686f74766563746f7273) then (match (GenVec::vgVectors archive) + | Option.none => (refused 0x746865206f7261636c652066696c657320617265206e6f7420696e2074686520726571756573740a) + | Option.some v => (written v)) else 0x696e76616c6964)))), + axioms: [Quot.sound, propext] +} + definition{ name: dispatch, parameters: [value : Bytes], @@ -75,7 +86,7 @@ | Option.none => (refused 0x74686520646f63756d656e74206973206e6f7420492d4a534f4e0a) | Option.some c => (written c)) else (if (Foundation.Tar::sameBytes name 0x6a63737061697273) then (let r : GenJcs::JcReport := (GenJcs::jcPairs archive); (if ((Foundation.Bytes::byteLength (project r failed)) =? 0) then (written (project r passed)) else (refused (project r failed)))) else (if (Foundation.Tar::sameBytes name 0x6a63736e756d62657273) then (let r : GenJcs::JcReport := (GenJcs::jcRows (sliceOr archive 512 (Foundation.Tar::entrySize archive 0))); (if ((Foundation.Bytes::byteLength (project r failed)) =? 0) then (written (project r passed)) else (refused (project r failed)))) else (if (Foundation.Tar::sameBytes name 0x61646472657373) then (match (GenAddr::adAddress (sliceOr archive 512 (Foundation.Tar::entrySize archive 0))) | Option.none => (refused 0x74686520646f63756d656e74206973206e6f7420492d4a534f4e0a) - | Option.some a => (written (Foundation.Bytes::appendBytes a 0x0a))) else (if (Foundation.Tar::sameBytes name 0x73686173686f7274) then (let r : GenJcs::JcReport := (GenAddr::adShort (sliceOr archive 512 (Foundation.Tar::entrySize archive 0))); (if ((Foundation.Bytes::byteLength (project r failed)) =? 0) then (written (project r passed)) else (refused (project r failed)))) else (if (Foundation.Tar::sameBytes name 0x7368616d6f6e7465) then (let r : GenJcs::JcReport := (GenAddr::adMonte (sliceOr archive 512 (Foundation.Tar::entrySize archive 0))); (if ((Foundation.Bytes::byteLength (project r failed)) =? 0) then (written (project r passed)) else (refused (project r failed)))) else (if (Foundation.Tar::sameBytes name 0x6c6f636b636865636b) then (let r : GenJcs::JcReport := (GenAddr::adLock archive); (if ((Foundation.Bytes::byteLength (project r failed)) =? 0) then (written (project r passed)) else (refused (project r failed)))) else 0x696e76616c6964)))))))))))))))), + | Option.some a => (written (Foundation.Bytes::appendBytes a 0x0a))) else (dispatchMore name archive)))))))))))))), axioms: [Quot.sound, propext] } \end{semanticmodule} diff --git a/generators/snapshot/steps.json b/generators/snapshot/steps.json index dc195ff2..7dbafc0d 100644 --- a/generators/snapshot/steps.json +++ b/generators/snapshot/steps.json @@ -1,5 +1,5 @@ { - "comment": "The steps of the snapshot program (generators/snapshot/), run in order by tools/generators/run.sh. jsonpatchoracle applies every case of the json-patch-tests suite (app/specs/oracle/json-patch-tests) as RFC 6902 says; jcspairs canonicalizes every input of the RFC 8785 author's test data (app/specs/oracle/json-canonicalization) and compares it with its output; jcsnumbers serializes every row of RFC 8785 Appendix B (app/specs/oracle/rfc8785) and writes the rows it held. Each refuses on any difference. shashort and shamonte hash every NIST CAVP SHA-256 message and Monte Carlo checkpoint (app/specs/oracle/nist-cavp-sha256) with the SHA-256 that snapshot addresses use; lockcheck hashes every vendored oracle file and refuses one whose SHA-256 is not the one its lock.json pins, or a file the lock does not list.", + "comment": "The steps of the snapshot program (generators/snapshot/), run in order by tools/generators/run.sh. jsonpatchoracle applies every case of the json-patch-tests suite (app/specs/oracle/json-patch-tests) as RFC 6902 says; jcspairs canonicalizes every input of the RFC 8785 author's test data (app/specs/oracle/json-canonicalization) and compares it with its output; jcsnumbers serializes every row of RFC 8785 Appendix B (app/specs/oracle/rfc8785) and writes the rows it held. Each refuses on any difference. shashort and shamonte hash every NIST CAVP SHA-256 message and Monte Carlo checkpoint (app/specs/oracle/nist-cavp-sha256) with the SHA-256 that snapshot addresses use; lockcheck hashes every vendored oracle file and refuses one whose SHA-256 is not the one its lock.json pins, or a file the lock does not list. snapshotvectors writes the acceptance vectors of the snapshot guest (app/specs/snapshot/spec.json) from those oracles: apply, every case of spec_tests.json (RFC 6902 Appendix A) as [document, patch], answered by the RFC 8785 form of its expected document or by refusal for an error case; canonical, every input of the RFC 8785 author's test data, answered by its output byte for byte; address, the same inputs, answered by sha256: and the SHA-256 of that output; sha256, every message of NIST CAVP SHA256ShortMsg.rsp as its Len and Msg lines, answered by its MD line.", "steps": [ { "generator": "jsonpatchoracle", @@ -90,6 +90,26 @@ "app/specs/oracle/rfc8785/rfc8785-appendix-b.txt" ], "output": ".gen/lock-rfc8785" + }, + { + "generator": "snapshotvectors", + "inputs": [ + "app/specs/oracle/json-canonicalization/input/arrays.json", + "app/specs/oracle/json-canonicalization/input/french.json", + "app/specs/oracle/json-canonicalization/input/structures.json", + "app/specs/oracle/json-canonicalization/input/unicode.json", + "app/specs/oracle/json-canonicalization/input/values.json", + "app/specs/oracle/json-canonicalization/input/weird.json", + "app/specs/oracle/json-canonicalization/output/arrays.json", + "app/specs/oracle/json-canonicalization/output/french.json", + "app/specs/oracle/json-canonicalization/output/structures.json", + "app/specs/oracle/json-canonicalization/output/unicode.json", + "app/specs/oracle/json-canonicalization/output/values.json", + "app/specs/oracle/json-canonicalization/output/weird.json", + "app/specs/oracle/json-patch-tests/spec_tests.json", + "app/specs/oracle/nist-cavp-sha256/SHA256ShortMsg.rsp" + ], + "output": "app/specs/snapshot/spec.json" } ] } diff --git a/site/snapshot/guest.mjs b/site/snapshot/guest.mjs new file mode 100644 index 00000000..e15564a8 --- /dev/null +++ b/site/snapshot/guest.mjs @@ -0,0 +1,31 @@ +// Generated by generators/guests from app/specs/guests (GU-01): the standalone +// guest of PrismSnapshot, built by tools/guests/build.sh from the modules the +// Prism compiles, so the Node suites run every request without the holo. Each +// exports holo_alloc(len) and holo_run(ptr, len) -> (outPtr << 32 | outLen); +// bytes whose SHA-256 is not the pinned one are refused before they compile. + +export const GUEST = { path: 'guest/snapshot.wasm', sha256: '041b56c0ddcb4a2525259b4e03dbb6de493832e4903bb3d59f3ae03c6db39768' }; + +const hex = (u8) => Array.from(u8, (b) => b.toString(16).padStart(2, '0')).join(''); +const encoder = new TextEncoder(); +const decoder = new TextDecoder('utf-8', { fatal: true }); + +async function compile(bytes, sha256) { + const got = hex(new Uint8Array(await crypto.subtle.digest('SHA-256', bytes))); + if (got !== sha256) throw Object.assign(new Error(`guest refused: fingerprint ${got} is not ${sha256}`), { code: 'snapshot.guest' }); + return WebAssembly.compile(bytes); +} + +function run(x, line) { + const input = encoder.encode(line); + const ptr = x.holo_alloc(input.length); + new Uint8Array(x.memory.buffer, ptr, input.length).set(input); + const packed = BigInt.asUintN(64, BigInt(x.holo_run(ptr, input.length))); + return decoder.decode(new Uint8Array(x.memory.buffer, Number(packed >> 32n), Number(packed & 0xffffffffn))); +} + +// A fresh instance per request: the guest's allocator never frees, and no state carries over. +export async function openGuest(bytes, sha256) { + const module = await compile(bytes, sha256); + return async (line) => run((await WebAssembly.instantiate(module, {})).exports, line); +} diff --git a/site/snapshot/guest/snapshot.wasm b/site/snapshot/guest/snapshot.wasm new file mode 100644 index 00000000..5dd8d01b Binary files /dev/null and b/site/snapshot/guest/snapshot.wasm differ diff --git a/test/parts/parts.txt b/test/parts/parts.txt index b878ff68..34d801b2 100644 --- a/test/parts/parts.txt +++ b/test/parts/parts.txt @@ -64,6 +64,7 @@ app/src/PrismRouter.lex.tex app/src/PrismRouterProofs.lex.tex app/src/PrismScxml.lex.tex app/src/PrismSenses.lex.tex +app/src/PrismSnapshot.lex.tex app/src/PrismSosaTable.lex.tex app/src/PrismSource.lex.tex app/src/PrismSourceProofs.lex.tex @@ -149,6 +150,7 @@ site/router/router.mjs site/router/table.mjs site/scxml/guest.mjs site/senses/guest.mjs +site/snapshot/guest.mjs site/source/declared.mjs site/source/exports.mjs site/source/services.mjs diff --git a/test/standards/generated/rfc6901.jsonl b/test/standards/generated/rfc6901.jsonl new file mode 100644 index 00000000..3f15ebac --- /dev/null +++ b/test/standards/generated/rfc6901.jsonl @@ -0,0 +1,3 @@ +{"id": "rfc6901-4-a29c85e1", "kind": "must", "ref": "RFC 6901 4", "text": "o If the currently referenced value is a JSON array, the reference token MUST contain either:"} +{"id": "rfc6901-5-3520c6ca", "kind": "must", "ref": "RFC 6901 5", "text": "Per [RFC4627], Section 2.5, all instances of quotation mark '\"' (%x22), reverse solidus '\\' (%x5C), and control (%x00-1F) characters MUST be escaped."} +{"id": "rfc6901-7-c1ea989d", "kind": "should", "ref": "RFC 6901 7", "text": "An application of JSON Pointer SHOULD specify the impact and handling of each type of error."} diff --git a/test/standards/generated/rfc6902.jsonl b/test/standards/generated/rfc6902.jsonl new file mode 100644 index 00000000..8fc5efbb --- /dev/null +++ b/test/standards/generated/rfc6902.jsonl @@ -0,0 +1,18 @@ +{"id": "rfc6902-4-5d946f07", "kind": "must", "ref": "RFC 6902 4", "text": "Operation objects MUST have exactly one \"op\" member, whose value indicates the operation to perform."} +{"id": "rfc6902-4-174d230e", "kind": "must", "ref": "RFC 6902 4", "text": "Its value MUST be one of \"add\", \"remove\", \"replace\", \"move\", \"copy\", or \"test\"; other values are errors."} +{"id": "rfc6902-4-30dabaa7", "kind": "must", "ref": "RFC 6902 4", "text": "Additionally, operation objects MUST have exactly one \"path\" member."} +{"id": "rfc6902-4-d4abf196", "kind": "must", "ref": "RFC 6902 4", "text": "Members that are not explicitly defined for the operation in question MUST be ignored (i.e., the operation will complete as if the undefined member did not appear in the object)."} +{"id": "rfc6902-4.1-ae9fcb99", "kind": "must", "ref": "RFC 6902 4.1", "text": "The operation object MUST contain a \"value\" member whose content specifies the value to be added."} +{"id": "rfc6902-4.1-06d0e10d", "kind": "must", "ref": "RFC 6902 4.1", "text": "When the operation is applied, the target location MUST reference one of:"} +{"id": "rfc6902-4.1-dd5c908f", "kind": "must", "ref": "RFC 6902 4.1", "text": "The specified index MUST NOT be greater than the number of elements in the array."} +{"id": "rfc6902-4.2-2b1ef42f", "kind": "must", "ref": "RFC 6902 4.2", "text": "The target location MUST exist for the operation to be successful."} +{"id": "rfc6902-4.3-460c075d", "kind": "must", "ref": "RFC 6902 4.3", "text": "The operation object MUST contain a \"value\" member whose content specifies the replacement value."} +{"id": "rfc6902-4.3-2b1ef42f", "kind": "must", "ref": "RFC 6902 4.3", "text": "The target location MUST exist for the operation to be successful."} +{"id": "rfc6902-4.4-96f491da", "kind": "must", "ref": "RFC 6902 4.4", "text": "The operation object MUST contain a \"from\" member, which is a string containing a JSON Pointer value that references the location in the target document to move the value from."} +{"id": "rfc6902-4.4-c85200d6", "kind": "must", "ref": "RFC 6902 4.4", "text": "The \"from\" location MUST exist for the operation to be successful."} +{"id": "rfc6902-4.4-8bf2ea5e", "kind": "must", "ref": "RFC 6902 4.4", "text": "The \"from\" location MUST NOT be a proper prefix of the \"path\" location; i.e., a location cannot be moved into one of its children."} +{"id": "rfc6902-4.5-2c90fd3c", "kind": "must", "ref": "RFC 6902 4.5", "text": "The operation object MUST contain a \"from\" member, which is a string containing a JSON Pointer value that references the location in the target document to copy the value from."} +{"id": "rfc6902-4.5-c85200d6", "kind": "must", "ref": "RFC 6902 4.5", "text": "The \"from\" location MUST exist for the operation to be successful."} +{"id": "rfc6902-4.6-dca29c99", "kind": "must", "ref": "RFC 6902 4.6", "text": "The operation object MUST contain a \"value\" member that conveys the value to be compared to the target location's value."} +{"id": "rfc6902-4.6-159a78dd", "kind": "must", "ref": "RFC 6902 4.6", "text": "The target location MUST be equal to the \"value\" value for the operation to be considered successful."} +{"id": "rfc6902-5-ec058a4b", "kind": "should", "ref": "RFC 6902 5", "text": "If a normative requirement is violated by a JSON Patch document, or if an operation is not successful, evaluation of the JSON Patch document SHOULD terminate and application of the entire patch document SHALL NOT be deemed successful."} diff --git a/test/standards/generated/rfc8785.jsonl b/test/standards/generated/rfc8785.jsonl new file mode 100644 index 00000000..32b231c0 --- /dev/null +++ b/test/standards/generated/rfc8785.jsonl @@ -0,0 +1,27 @@ +{"id": "rfc8785-3-4f497a80", "kind": "should", "ref": "RFC 8785 3", "text": "Appendix F describes the RECOMMENDED way of adding JCS support to existing JSON tools."} +{"id": "rfc8785-3.1-321d353e", "kind": "must", "ref": "RFC 8785 3.1", "text": "Irrespective of the method used, the data to be serialized MUST be adapted for I-JSON [RFC7493] formatting, which implies the following:"} +{"id": "rfc8785-3.1-95a5d7cd", "kind": "must", "ref": "RFC 8785 3.1", "text": "* JSON objects MUST NOT exhibit duplicate property names."} +{"id": "rfc8785-3.1-14f3ad1b", "kind": "must", "ref": "RFC 8785 3.1", "text": "* JSON string data MUST be expressible as Unicode [UNICODE]."} +{"id": "rfc8785-3.1-ffeae857", "kind": "must", "ref": "RFC 8785 3.1", "text": "* JSON number data MUST be expressible as IEEE 754 [IEEE754] double- precision values."} +{"id": "rfc8785-3.1-b5bb857d", "kind": "should", "ref": "RFC 8785 3.1", "text": "For applications needing higher precision or longer integers than offered by IEEE 754 double precision, it is RECOMMENDED to represent such numbers as JSON strings; see Appendix D for details on how this can be performed in an interoperable and extensible way."} +{"id": "rfc8785-3.1-19737ffb", "kind": "must", "ref": "RFC 8785 3.1", "text": "An additional constraint is that parsed JSON string data MUST NOT be altered during subsequent serializations."} +{"id": "rfc8785-3.1-89b727e4", "kind": "must", "ref": "RFC 8785 3.1", "text": "That is, all components involved in a scheme depending on JCS MUST preserve Unicode string data \"as is\"."} +{"id": "rfc8785-3.2.1-f7828dcb", "kind": "must", "ref": "RFC 8785 3.2.1", "text": "Whitespace between JSON tokens MUST NOT be emitted."} +{"id": "rfc8785-3.2.2.1-d73f46ac", "kind": "must", "ref": "RFC 8785 3.2.2.1", "text": "In accordance with JSON [RFC8259], the literals \"null\", \"true\", and \"false\" MUST be serialized as null, true, and false, respectively."} +{"id": "rfc8785-3.2.2.2-7e32fd81", "kind": "must", "ref": "RFC 8785 3.2.2.2", "text": "For JSON string data (which includes JSON object property names as well), each Unicode code point MUST be serialized as described below (see Section 24.3.2.2 of [ECMA-262]):"} +{"id": "rfc8785-3.2.2.2-5658b4ab", "kind": "must", "ref": "RFC 8785 3.2.2.2", "text": "* If the Unicode value falls within the traditional ASCII control character range (U+0000 through U+001F), it MUST be serialized using lowercase hexadecimal Unicode notation (\\uhhhh) unless it is in the set of predefined JSON control characters U+0008, U+0009, U+000A, U+000C, or U+000D, which MUST be serialized as \\b, \\t, \\n, \\f, and \\r, respectively."} +{"id": "rfc8785-3.2.2.2-4e479461", "kind": "must", "ref": "RFC 8785 3.2.2.2", "text": "* If the Unicode value is outside of the ASCII control character range, it MUST be serialized \"as is\" unless it is equivalent to U+005C (\\) or U+0022 (\"), which MUST be serialized as \\\\ and \\\", respectively."} +{"id": "rfc8785-3.2.2.2-bdf9de0e", "kind": "must", "ref": "RFC 8785 3.2.2.2", "text": "Finally, the resulting sequence of Unicode code points MUST be enclosed in double quotes (\")."} +{"id": "rfc8785-3.2.2.2-2eedd5b0", "kind": "must", "ref": "RFC 8785 3.2.2.2", "text": "Since invalid Unicode data like \"lone surrogates\" (e.g., U+DEAD) may lead to interoperability issues including broken signatures, occurrences of such data MUST cause a compliant JCS implementation to terminate with an appropriate error."} +{"id": "rfc8785-3.2.2.3-44488107", "kind": "must", "ref": "RFC 8785 3.2.2.3", "text": "Such data MUST be serialized according to Section 7.1.12.1 of [ECMA-262], including the \"Note 2\" enhancement."} +{"id": "rfc8785-3.2.2.3-2f82800e", "kind": "must", "ref": "RFC 8785 3.2.2.3", "text": "Since Not a Number (NaN) and Infinity are not permitted in JSON, occurrences of NaN or Infinity MUST cause a compliant JCS implementation to terminate with an appropriate error."} +{"id": "rfc8785-3.2.3-8ee23ccb", "kind": "must", "ref": "RFC 8785 3.2.3", "text": "* JSON object properties MUST be sorted recursively, which means that JSON child Objects MUST have their properties sorted as well."} +{"id": "rfc8785-3.2.3-36b63a1b", "kind": "must", "ref": "RFC 8785 3.2.3", "text": "* JSON array data MUST also be scanned for the presence of JSON objects (if an object is found, then its properties MUST be sorted), but array element order MUST NOT be changed."} +{"id": "rfc8785-3.2.3-0281d99a", "kind": "must", "ref": "RFC 8785 3.2.3", "text": "When a JSON object is about to have its properties sorted, the following measures MUST be adhered to:"} +{"id": "rfc8785-3.2.4-42882237", "kind": "must", "ref": "RFC 8785 3.2.4", "text": "Finally, in order to create a platform-independent representation, the result of the preceding step MUST be encoded in UTF-8."} +{"id": "rfc8785-5-f7ceb343", "kind": "must", "ref": "RFC 8785 5", "text": "When JCS is applied to signature schemes like the one described in Appendix F, applications MUST perform the following operations before acting upon received data:"} +{"id": "rfc8785-5-a93c4d93", "kind": "must", "ref": "RFC 8785 5", "text": "If any of these steps fail, the operation in progress MUST be aborted."} +{"id": "rfc8785-B-f6a97ac2", "kind": "should", "ref": "RFC 8785 B", "text": "(1) For maximum compliance with the ECMAScript \"JSON\" object, values that are to be interpreted as true integers SHOULD be in the range -9007199254740991 to 9007199254740991."} +{"id": "rfc8785-D-c076c308", "kind": "must", "ref": "RFC 8785 D", "text": "Due to the above, numbers that do not have a natural place in the current JSON ecosystem MUST be wrapped using the JSON string type."} +{"id": "rfc8785-E-0ee0bc2a", "kind": "must", "ref": "RFC 8785 E", "text": "This can, depending on JSON parsing method, lead to interoperability problems, which MUST be dealt with by JCS-compliant applications targeting a wider audience."} +{"id": "rfc8785-E-cc549aff", "kind": "must", "ref": "RFC 8785 E", "text": "That is, stream- and schema-based parsing MUST treat subtypes as \"pure\" (immutable) JSON string types and perform the actual conversion to the designated native type in a subsequent step."} diff --git a/test/standards/requirements.json b/test/standards/requirements.json index a3ae9e86..2361da1e 100644 --- a/test/standards/requirements.json +++ b/test/standards/requirements.json @@ -6460,6 +6460,136 @@ "text": "The property value KIND:device registered by IANA's vCard Elements registry is read as its RFC defines it" } ], + "rfc6901": [ + { + "id": "rfc6901-4-a29c85e1", + "kind": "must", + "ref": "RFC 6901 4", + "text": "o If the currently referenced value is a JSON array, the reference token MUST contain either:" + }, + { + "id": "rfc6901-5-3520c6ca", + "kind": "must", + "ref": "RFC 6901 5", + "text": "Per [RFC4627], Section 2.5, all instances of quotation mark '\"' (%x22), reverse solidus '\\' (%x5C), and control (%x00-1F) characters MUST be escaped." + }, + { + "id": "rfc6901-7-c1ea989d", + "kind": "should", + "ref": "RFC 6901 7", + "text": "An application of JSON Pointer SHOULD specify the impact and handling of each type of error." + } + ], + "rfc6902": [ + { + "id": "rfc6902-4-174d230e", + "kind": "must", + "ref": "RFC 6902 4", + "text": "Its value MUST be one of \"add\", \"remove\", \"replace\", \"move\", \"copy\", or \"test\"; other values are errors." + }, + { + "id": "rfc6902-4-30dabaa7", + "kind": "must", + "ref": "RFC 6902 4", + "text": "Additionally, operation objects MUST have exactly one \"path\" member." + }, + { + "id": "rfc6902-4-5d946f07", + "kind": "must", + "ref": "RFC 6902 4", + "text": "Operation objects MUST have exactly one \"op\" member, whose value indicates the operation to perform." + }, + { + "id": "rfc6902-4-d4abf196", + "kind": "must", + "ref": "RFC 6902 4", + "text": "Members that are not explicitly defined for the operation in question MUST be ignored (i.e., the operation will complete as if the undefined member did not appear in the object)." + }, + { + "id": "rfc6902-4.1-06d0e10d", + "kind": "must", + "ref": "RFC 6902 4.1", + "text": "When the operation is applied, the target location MUST reference one of:" + }, + { + "id": "rfc6902-4.1-ae9fcb99", + "kind": "must", + "ref": "RFC 6902 4.1", + "text": "The operation object MUST contain a \"value\" member whose content specifies the value to be added." + }, + { + "id": "rfc6902-4.1-dd5c908f", + "kind": "must", + "ref": "RFC 6902 4.1", + "text": "The specified index MUST NOT be greater than the number of elements in the array." + }, + { + "id": "rfc6902-4.2-2b1ef42f", + "kind": "must", + "ref": "RFC 6902 4.2", + "text": "The target location MUST exist for the operation to be successful." + }, + { + "id": "rfc6902-4.3-2b1ef42f", + "kind": "must", + "ref": "RFC 6902 4.3", + "text": "The target location MUST exist for the operation to be successful." + }, + { + "id": "rfc6902-4.3-460c075d", + "kind": "must", + "ref": "RFC 6902 4.3", + "text": "The operation object MUST contain a \"value\" member whose content specifies the replacement value." + }, + { + "id": "rfc6902-4.4-8bf2ea5e", + "kind": "must", + "ref": "RFC 6902 4.4", + "text": "The \"from\" location MUST NOT be a proper prefix of the \"path\" location; i.e., a location cannot be moved into one of its children." + }, + { + "id": "rfc6902-4.4-96f491da", + "kind": "must", + "ref": "RFC 6902 4.4", + "text": "The operation object MUST contain a \"from\" member, which is a string containing a JSON Pointer value that references the location in the target document to move the value from." + }, + { + "id": "rfc6902-4.4-c85200d6", + "kind": "must", + "ref": "RFC 6902 4.4", + "text": "The \"from\" location MUST exist for the operation to be successful." + }, + { + "id": "rfc6902-4.5-2c90fd3c", + "kind": "must", + "ref": "RFC 6902 4.5", + "text": "The operation object MUST contain a \"from\" member, which is a string containing a JSON Pointer value that references the location in the target document to copy the value from." + }, + { + "id": "rfc6902-4.5-c85200d6", + "kind": "must", + "ref": "RFC 6902 4.5", + "text": "The \"from\" location MUST exist for the operation to be successful." + }, + { + "id": "rfc6902-4.6-159a78dd", + "kind": "must", + "ref": "RFC 6902 4.6", + "text": "The target location MUST be equal to the \"value\" value for the operation to be considered successful." + }, + { + "id": "rfc6902-4.6-dca29c99", + "kind": "must", + "ref": "RFC 6902 4.6", + "text": "The operation object MUST contain a \"value\" member that conveys the value to be compared to the target location's value." + }, + { + "id": "rfc6902-5-ec058a4b", + "kind": "should", + "ref": "RFC 6902 5", + "text": "If a normative requirement is violated by a JSON Patch document, or if an operation is not successful, evaluation of the JSON Patch document SHOULD terminate and application of the entire patch document SHALL NOT be deemed successful." + } + ], "rfc7852": [ { "id": "rfc7852-parameter-value-TYPE-main-number-TEL", @@ -6500,6 +6630,170 @@ "text": "The property CONTACT-URI registered by IANA's vCard Elements registry is read as its RFC defines it" } ], + "rfc8785": [ + { + "id": "rfc8785-3-4f497a80", + "kind": "should", + "ref": "RFC 8785 3", + "text": "Appendix F describes the RECOMMENDED way of adding JCS support to existing JSON tools." + }, + { + "id": "rfc8785-3.1-14f3ad1b", + "kind": "must", + "ref": "RFC 8785 3.1", + "text": "* JSON string data MUST be expressible as Unicode [UNICODE]." + }, + { + "id": "rfc8785-3.1-19737ffb", + "kind": "must", + "ref": "RFC 8785 3.1", + "text": "An additional constraint is that parsed JSON string data MUST NOT be altered during subsequent serializations." + }, + { + "id": "rfc8785-3.1-321d353e", + "kind": "must", + "ref": "RFC 8785 3.1", + "text": "Irrespective of the method used, the data to be serialized MUST be adapted for I-JSON [RFC7493] formatting, which implies the following:" + }, + { + "id": "rfc8785-3.1-89b727e4", + "kind": "must", + "ref": "RFC 8785 3.1", + "text": "That is, all components involved in a scheme depending on JCS MUST preserve Unicode string data \"as is\"." + }, + { + "id": "rfc8785-3.1-95a5d7cd", + "kind": "must", + "ref": "RFC 8785 3.1", + "text": "* JSON objects MUST NOT exhibit duplicate property names." + }, + { + "id": "rfc8785-3.1-b5bb857d", + "kind": "should", + "ref": "RFC 8785 3.1", + "text": "For applications needing higher precision or longer integers than offered by IEEE 754 double precision, it is RECOMMENDED to represent such numbers as JSON strings; see Appendix D for details on how this can be performed in an interoperable and extensible way." + }, + { + "id": "rfc8785-3.1-ffeae857", + "kind": "must", + "ref": "RFC 8785 3.1", + "text": "* JSON number data MUST be expressible as IEEE 754 [IEEE754] double- precision values." + }, + { + "id": "rfc8785-3.2.1-f7828dcb", + "kind": "must", + "ref": "RFC 8785 3.2.1", + "text": "Whitespace between JSON tokens MUST NOT be emitted." + }, + { + "id": "rfc8785-3.2.2.1-d73f46ac", + "kind": "must", + "ref": "RFC 8785 3.2.2.1", + "text": "In accordance with JSON [RFC8259], the literals \"null\", \"true\", and \"false\" MUST be serialized as null, true, and false, respectively." + }, + { + "id": "rfc8785-3.2.2.2-2eedd5b0", + "kind": "must", + "ref": "RFC 8785 3.2.2.2", + "text": "Since invalid Unicode data like \"lone surrogates\" (e.g., U+DEAD) may lead to interoperability issues including broken signatures, occurrences of such data MUST cause a compliant JCS implementation to terminate with an appropriate error." + }, + { + "id": "rfc8785-3.2.2.2-4e479461", + "kind": "must", + "ref": "RFC 8785 3.2.2.2", + "text": "* If the Unicode value is outside of the ASCII control character range, it MUST be serialized \"as is\" unless it is equivalent to U+005C (\\) or U+0022 (\"), which MUST be serialized as \\\\ and \\\", respectively." + }, + { + "id": "rfc8785-3.2.2.2-5658b4ab", + "kind": "must", + "ref": "RFC 8785 3.2.2.2", + "text": "* If the Unicode value falls within the traditional ASCII control character range (U+0000 through U+001F), it MUST be serialized using lowercase hexadecimal Unicode notation (\\uhhhh) unless it is in the set of predefined JSON control characters U+0008, U+0009, U+000A, U+000C, or U+000D, which MUST be serialized as \\b, \\t, \\n, \\f, and \\r, respectively." + }, + { + "id": "rfc8785-3.2.2.2-7e32fd81", + "kind": "must", + "ref": "RFC 8785 3.2.2.2", + "text": "For JSON string data (which includes JSON object property names as well), each Unicode code point MUST be serialized as described below (see Section 24.3.2.2 of [ECMA-262]):" + }, + { + "id": "rfc8785-3.2.2.2-bdf9de0e", + "kind": "must", + "ref": "RFC 8785 3.2.2.2", + "text": "Finally, the resulting sequence of Unicode code points MUST be enclosed in double quotes (\")." + }, + { + "id": "rfc8785-3.2.2.3-2f82800e", + "kind": "must", + "ref": "RFC 8785 3.2.2.3", + "text": "Since Not a Number (NaN) and Infinity are not permitted in JSON, occurrences of NaN or Infinity MUST cause a compliant JCS implementation to terminate with an appropriate error." + }, + { + "id": "rfc8785-3.2.2.3-44488107", + "kind": "must", + "ref": "RFC 8785 3.2.2.3", + "text": "Such data MUST be serialized according to Section 7.1.12.1 of [ECMA-262], including the \"Note 2\" enhancement." + }, + { + "id": "rfc8785-3.2.3-0281d99a", + "kind": "must", + "ref": "RFC 8785 3.2.3", + "text": "When a JSON object is about to have its properties sorted, the following measures MUST be adhered to:" + }, + { + "id": "rfc8785-3.2.3-36b63a1b", + "kind": "must", + "ref": "RFC 8785 3.2.3", + "text": "* JSON array data MUST also be scanned for the presence of JSON objects (if an object is found, then its properties MUST be sorted), but array element order MUST NOT be changed." + }, + { + "id": "rfc8785-3.2.3-8ee23ccb", + "kind": "must", + "ref": "RFC 8785 3.2.3", + "text": "* JSON object properties MUST be sorted recursively, which means that JSON child Objects MUST have their properties sorted as well." + }, + { + "id": "rfc8785-3.2.4-42882237", + "kind": "must", + "ref": "RFC 8785 3.2.4", + "text": "Finally, in order to create a platform-independent representation, the result of the preceding step MUST be encoded in UTF-8." + }, + { + "id": "rfc8785-5-a93c4d93", + "kind": "must", + "ref": "RFC 8785 5", + "text": "If any of these steps fail, the operation in progress MUST be aborted." + }, + { + "id": "rfc8785-5-f7ceb343", + "kind": "must", + "ref": "RFC 8785 5", + "text": "When JCS is applied to signature schemes like the one described in Appendix F, applications MUST perform the following operations before acting upon received data:" + }, + { + "id": "rfc8785-B-f6a97ac2", + "kind": "should", + "ref": "RFC 8785 B", + "text": "(1) For maximum compliance with the ECMAScript \"JSON\" object, values that are to be interpreted as true integers SHOULD be in the range -9007199254740991 to 9007199254740991." + }, + { + "id": "rfc8785-D-c076c308", + "kind": "must", + "ref": "RFC 8785 D", + "text": "Due to the above, numbers that do not have a natural place in the current JSON ecosystem MUST be wrapped using the JSON string type." + }, + { + "id": "rfc8785-E-0ee0bc2a", + "kind": "must", + "ref": "RFC 8785 E", + "text": "This can, depending on JSON parsing method, lead to interoperability problems, which MUST be dealt with by JCS-compliant applications targeting a wider audience." + }, + { + "id": "rfc8785-E-cc549aff", + "kind": "must", + "ref": "RFC 8785 E", + "text": "That is, stream- and schema-based parsing MUST treat subtypes as \"pure\" (immutable) JSON string types and perform the actual conversion to the designated native type in a subsequent step." + } + ], "rfc9554": [ { "id": "rfc9554-2.1-17a21ce6",