Created
January 23, 2018 14:57
-
-
Save grbIzl/14541e57f50b3ceae9831512c8234624 to your computer and use it in GitHub Desktop.
Trivial secret store permissioning contract
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.11; | |
contract SecretStorePermissions { | |
mapping (bytes32 => address[]) keyOwners; | |
mapping (uint => bytes32) keysIndex; | |
uint keysCount; | |
function addKey(address[] users, bytes32 key) public { | |
keyOwners[key] = users; | |
keysIndex[keysCount] = key; | |
keysCount = keysCount + 1; | |
} | |
function checkPermissions(address user, bytes32 document) public constant returns (bool) { | |
bool key_found = false; | |
address[] owners; | |
for(uint i = 0; i < keysCount; i++) { | |
if (keysIndex[i] == document) { | |
key_found = true; | |
owners = keyOwners[keysIndex[i]]; | |
} | |
} | |
if (!key_found) { | |
return false; | |
} | |
for (uint j = 0; j < owners.length; j++) { | |
if (owners[j] == user) { | |
return true; | |
} | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment