Skip to content

Commit ce43443

Browse files
authored
feat: smithy for virtual fields (#71)
* feat: smithy for virtual fields * use union for Transform * zero-based plus GetSegments
1 parent 7a570d6 commit ce43443

16 files changed

+1445
-3
lines changed

DynamoDbEncryptionMiddlewareInternal/Model/AwsCryptographyDynamoDbEncryptionTypes.dfy

+62-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ include "../../private-aws-encryption-sdk-dafny-staging/StandardLibrary/src/Inde
6767
nameonly version: VersionNumber ,
6868
nameonly keyring: AwsCryptographyMaterialProvidersTypes.IKeyring ,
6969
nameonly standardBeacons: Option<StandardBeaconList> ,
70-
nameonly compoundBeacons: Option<CompoundBeaconList>
70+
nameonly compoundBeacons: Option<CompoundBeaconList> ,
71+
nameonly virtualFields: Option<VirtualFieldList>
7172
)
7273
type BeaconVersionList = x: seq<BeaconVersion> | IsValid_BeaconVersionList(x) witness *
7374
predicate method IsValid_BeaconVersionList(x: seq<BeaconVersion>) {
@@ -771,6 +772,31 @@ include "../../private-aws-encryption-sdk-dafny-staging/StandardLibrary/src/Inde
771772
)
772773
datatype GetItemOutputTransformOutput = | GetItemOutputTransformOutput (
773774
nameonly transformedOutput: ComAmazonawsDynamodbTypes.GetItemOutput
775+
)
776+
datatype GetPrefix = | GetPrefix (
777+
nameonly length: int32
778+
)
779+
datatype GetSegment = | GetSegment (
780+
nameonly split: Char ,
781+
nameonly index: int32
782+
)
783+
datatype GetSegments = | GetSegments (
784+
nameonly split: Char ,
785+
nameonly low: int32 ,
786+
nameonly high: int32
787+
)
788+
datatype GetSubstring = | GetSubstring (
789+
nameonly low: int32 ,
790+
nameonly high: int32
791+
)
792+
datatype GetSuffix = | GetSuffix (
793+
nameonly length: int32
794+
)
795+
datatype Insert = | Insert (
796+
nameonly literal: string
797+
)
798+
datatype Lower = | Lower (
799+
774800
)
775801
datatype NonSensitivePart = | NonSensitivePart (
776802
nameonly name: string ,
@@ -902,10 +928,42 @@ include "../../private-aws-encryption-sdk-dafny-staging/StandardLibrary/src/Inde
902928
)
903929
datatype UpdateTableOutputTransformOutput = | UpdateTableOutputTransformOutput (
904930
nameonly transformedOutput: ComAmazonawsDynamodbTypes.UpdateTableOutput
931+
)
932+
datatype Upper = | Upper (
933+
905934
)
906935
type VersionNumber = x: int32 | IsValid_VersionNumber(x) witness *
907936
predicate method IsValid_VersionNumber(x: int32) {
908937
( 1 <= x )
938+
}
939+
datatype VirtualField = | VirtualField (
940+
nameonly name: string ,
941+
nameonly parts: VirtualPartList
942+
)
943+
type VirtualFieldList = x: seq<VirtualField> | IsValid_VirtualFieldList(x) witness *
944+
predicate method IsValid_VirtualFieldList(x: seq<VirtualField>) {
945+
( 1 <= |x| )
946+
}
947+
datatype VirtualPart = | VirtualPart (
948+
nameonly loc: TerminalLocation ,
949+
nameonly trans: Option<VirtualTransformList>
950+
)
951+
type VirtualPartList = x: seq<VirtualPart> | IsValid_VirtualPartList(x) witness *
952+
predicate method IsValid_VirtualPartList(x: seq<VirtualPart>) {
953+
( 1 <= |x| )
954+
}
955+
datatype VirtualTransform =
956+
| upper(upper: Upper)
957+
| lower(lower: Lower)
958+
| insert(insert: Insert)
959+
| prefix(prefix: GetPrefix)
960+
| suffix(suffix: GetSuffix)
961+
| substring(substring: GetSubstring)
962+
| segment(segment: GetSegment)
963+
| segments(segments: GetSegments)
964+
type VirtualTransformList = x: seq<VirtualTransform> | IsValid_VirtualTransformList(x) witness *
965+
predicate method IsValid_VirtualTransformList(x: seq<VirtualTransform>) {
966+
( 1 <= |x| )
909967
}
910968
datatype Error =
911969
// Local Error structures are listed here
@@ -955,7 +1013,9 @@ include "../../private-aws-encryption-sdk-dafny-staging/StandardLibrary/src/Inde
9551013
function method DefaultDynamoDbEncryptionConfig(): DynamoDbEncryptionConfig
9561014
method DynamoDbEncryption(config: DynamoDbEncryptionConfig := DefaultDynamoDbEncryptionConfig())
9571015
returns (res: Result<DynamoDbEncryptionClient, Error>)
958-
// TODO smithy->Dafny needs to generate the following
1016+
// TODO smithy->Dafny correctly generates something equivalent the following
1017+
// but as a result DynamoDbEncryption.DynamoDbEncryption and TestFixtures.GetDynamoDbEncryption
1018+
// take too long to verify
9591019
///// MANUAL UPDATE STARTS HERE
9601020
requires
9611021
var cmms := set cfg | cfg in config.tableEncryptionConfigs.Values && cfg.cmm.Some? :: cfg.cmm.value;

DynamoDbEncryptionMiddlewareInternal/Model/DynamoDbEncryptionMiddlewareInternal.smithy

+103
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,21 @@ list BeaconVersionList {
124124
member: BeaconVersion
125125
}
126126

127+
@length(min: 1)
128+
list VirtualFieldList {
129+
member: VirtualField
130+
}
131+
132+
@length(min: 1)
133+
list VirtualPartList {
134+
member: VirtualPart
135+
}
136+
137+
@length(min: 1)
138+
list VirtualTransformList {
139+
member: VirtualTransform
140+
}
141+
127142
@length(min: 1)
128143
list StandardBeaconList {
129144
member: StandardBeacon
@@ -154,6 +169,93 @@ list ConstructorPartList {
154169
member: ConstructorPart
155170
}
156171

172+
structure VirtualField {
173+
@required
174+
name : String,
175+
@required
176+
parts : VirtualPartList,
177+
}
178+
179+
structure VirtualPart {
180+
@required
181+
loc : TerminalLocation,
182+
trans : VirtualTransformList,
183+
}
184+
185+
// Convert ASCII characters to upper case
186+
structure Upper {}
187+
188+
// Convert ASCII characters to lower case
189+
structure Lower {}
190+
191+
// Append this literal string
192+
structure Insert {
193+
@required
194+
literal : String
195+
}
196+
197+
// return the first part of the string
198+
// Positive length : return that many characters from the front
199+
// Negative length : exclude -length characters from the end
200+
// e.g. GetPrefix(-1) returns all but the last character
201+
structure GetPrefix {
202+
@required
203+
length : Integer
204+
}
205+
206+
// return the last part of the string
207+
// Positive length : return that many characters from the end
208+
// Negative length : exclude -length characters from the front
209+
// e.g. GetSuffix(-1) returns all but the first character
210+
structure GetSuffix {
211+
@required
212+
length : Integer
213+
}
214+
215+
// return range of characters, 0-based counting
216+
// low is inclusive, high is exclusive
217+
// negative numbers count from the end, -1 is the end of string
218+
// i.e. the whole string is GetSubstring(0, -1)
219+
// e.g. for "123456789"
220+
// GetSubstring(2, 6) == GetSubstring(2, -4) == "3456"
221+
structure GetSubstring {
222+
@required
223+
low : Integer,
224+
@required
225+
high : Integer,
226+
}
227+
228+
// split string on character, then return one piece.
229+
// 'index' has the same semantics as 'low' in GetSubstring
230+
structure GetSegment {
231+
@required
232+
split : Char,
233+
@required
234+
index : Integer
235+
}
236+
237+
// split string on character, then return range of pieces.
238+
// 'low' and 'high' have the same semantics as GetSubstring
239+
structure GetSegments {
240+
@required
241+
split : Char,
242+
@required
243+
low : Integer,
244+
@required
245+
high : Integer,
246+
}
247+
248+
union VirtualTransform {
249+
upper: Upper,
250+
lower: Lower,
251+
insert: Insert,
252+
prefix: GetPrefix,
253+
suffix: GetSuffix,
254+
substring : GetSubstring,
255+
segment : GetSegment,
256+
segments : GetSegments
257+
}
258+
157259
structure SensitivePart {
158260
@required
159261
name : String,
@@ -210,6 +312,7 @@ structure BeaconVersion {
210312
keyring: KeyringReference, // Must be Hierarchy Keyring
211313
standardBeacons : StandardBeaconList,
212314
compoundBeacons : CompoundBeaconList,
315+
virtualFields : VirtualFieldList,
213316
}
214317

215318
structure SearchConfig {

0 commit comments

Comments
 (0)