// generates a new trust chain with this as the root node public void GenerateRootChain() { if (Name.Length > TrustChainUtil.UNASSIGNED_DATA_SIZE - 1) { throw new ArgumentException("Name too long"); } var nameBytes = new byte[TrustChainUtil.UNASSIGNED_DATA_SIZE]; using (var ms = new MemoryStream(nameBytes)) using (var writer = new BinaryWriter(ms)) { writer.Write((byte)Name.Length); writer.Write(Encoding.UTF8.GetBytes(Name)); } byte[] rootChain = TrustChainUtil.GenerateNewChain(new TrustChainNode[0], PublicIdentity, PublicIdentity, Permission.All, Permission.All, nameBytes, privateKey); PermissionsHeld = Permission.All; PermissionsGrantable = Permission.All; AddTrustChain(rootChain); }
// generates a trust chain to pass to another client public byte[] GenerateNewChain(byte[] childId, Permission heldPermissions, Permission grantablePermissions, string name) { bool canGrant = CanGrantPermissions(heldPermissions, grantablePermissions); if (canGrant) { if (name.Length > TrustChainUtil.UNASSIGNED_DATA_SIZE - 1) { throw new ArgumentException("Name too long"); } byte[] nameBytes = new byte[TrustChainUtil.UNASSIGNED_DATA_SIZE]; nameBytes[0] = (byte)name.Length; Buffer.BlockCopy(Encoding.UTF8.GetBytes(name), 0, nameBytes, 1, name.Length); return(TrustChainUtil.GenerateNewChain(TrustChain, PublicIdentity, childId, heldPermissions, grantablePermissions, nameBytes, privateKey)); } else { throw new InvalidPermissionException($"Insufficient authorization to grant permissions"); } }