Sharp eyed students will have noticed that the TreasureChest type in the previous exercise wasn't that secure!
If you used the get_treasure function you had to supply the password, but you could still destructure the TreasureChest type to get the treasure without having to know the password.
Let's fix that by using an Opaque Type.
TreasureChest opaque type.The TreasureChest contains two fields:
String.The TreasureChest type must be opaque.
create function.This function takes two arguments:
String.The function returns a TreasureChest containing the password and the value.
If the password is shorter than 8 characters then the function should return an error saying Password must be at least 8 characters long.
open function.This function takes two arguments:
TreasureChest.String.If the password matches the password in the TreasureChest then the function should return the treasure, otherwise it should return an error saying Incorrect password.
Sharp eyed students will have noticed that the TreasureChest type in the previous exercise wasn't that secure!
If you used the get_treasure function you had to supply the password, but you could still destructure the TreasureChest type to get the treasure without having to know the password.
Let's fix that by using an Opaque Type.
TreasureChest opaque type.The TreasureChest contains two fields:
String.The TreasureChest type must be opaque.
create function.This function takes two arguments:
String.The function returns a TreasureChest containing the password and the value.
If the password is shorter than 8 characters then the function should return an error saying Password must be at least 8 characters long.
open function.This function takes two arguments:
TreasureChest.String.If the password matches the password in the TreasureChest then the function should return the treasure, otherwise it should return an error saying Incorrect password.