Example #1
0
func setupForGets() {
	hkidT := objects.HkidFromDString("39968110670682397993178679825250942322686997267223"+
		"4437068973021071131498376777586055610149840018574420844767320660902612889"+
		"4016152514163591905578729891874833", 10)

	//key for commit
	hkidC := objects.HkidFromDString("4629814823893296480016411334808793836186124559723200"+
		"9799621767537249764640887064630013835561124248209118706504211519889067517"+
		"10824965155500230480521264034469", 10)

	//Post blob
	testBlob := objects.Blob([]byte("testing")) //gen test blob
	err := services.PostBlob(testBlob)          //store test blob
	if err != nil {
		log.Println(err)
	}

	//post tag
	testTagPointingToTestBlob := objects.NewTag(
		objects.HID(testBlob.Hash()),
		"blob",
		"testBlob",
		nil,
		hkidT,
	) //gen test tag
	err = services.PostTag(testTagPointingToTestBlob) //post test tag
	if err != nil {
		log.Println(err)
	}

	//post list
	testListPiontingToTestTag := objects.NewList(testTagPointingToTestBlob.Hkid,
		"tag",
		"testTag") //gen test list
	err = services.PostBlob(testListPiontingToTestTag.Bytes()) //store test list
	if err != nil {
		log.Println(err)
	}

	// post commit
	testCommitPointingToTestList := objects.NewCommit(testListPiontingToTestTag.Hash(),
		hkidC) //gen test commit
	err = services.PostCommit(testCommitPointingToTestList) //post test commit
	if err != nil {
		log.Println(err)
	}
}
Example #2
0
func postBlob(data string) objects.HCID {
	testBlob := objects.Blob([]byte(data)) //gen test blob
	err := services.PostBlob(testBlob)     //store test blob
	if err != nil {
		log.Println(err)
	}
	return testBlob.Hash()

}
Example #3
0
func TestLowLevel(t *testing.T) {
	indata := objects.Blob([]byte("TestPostData"))
	services.PostBlob(indata)
	blobhcid, err := objects.HcidFromHex(
		"ca4c4244cee2bd8b8a35feddcd0ba36d775d68637b7f0b4d2558728d0752a2a2",
	)
	b, err := services.GetBlob(blobhcid)
	if !bytes.Equal(b.Hash(), blobhcid) {
		t.Fatalf("GetBlob Fail\nExpected: %s\nGot: %s\n", blobhcid, b.Hash()) //Changed
	}

	//6dedf7e580671bd90bc9d1f735c75a4f3692b697f8979a147e8edd64fab56e85
	testhkid := objects.HkidFromDString(
		"6523237356270560228617783789728329416595512649112249373497830592"+
			"0722414168936112160694238047304378604753005642729767620850685191"+
			"88612732562106886379081213385", 10)
	testCommit := objects.NewCommit(b.Hash(), testhkid)
	services.PostCommit(testCommit)
	c, err := services.GetCommit(testhkid)
	if err != nil {
		t.Fatalf("Get Commit Fail: %s", err)
	} else if !bytes.Equal(c.Hkid, testhkid) {
		t.Fatalf("Expected: %s Got: %s", testhkid, c.Hkid)
	} else if !c.Verify() {
		t.Fatalf("Commit Signature Invalid.")
	}

	//ede7bec713c93929751f18b1db46d4be3c95286bd5f2d92b9759ff02115dc312
	taghkid := objects.HkidFromDString(
		"4813315537186321970719165779488475377688633084782731170482174374"+
			"7256947679650787426167575073363006751150073195493002048627629373"+
			"76227751462258339344895829332", 10)
	lowlvlTag := objects.NewTag(
		objects.HID(b.Hash()),
		"blob",
		"testBlob",
		nil,
		taghkid,
	) //gen test tag
	services.PostTag(lowlvlTag)
	testtag, err := services.GetTag(taghkid, lowlvlTag.NameSegment)
	if err != nil {
		t.Fatalf("GetTag Fail. error: %s", err)
	} else if !bytes.Equal(testtag.Hkid, taghkid) {
		t.Fatalf("GetTag Fail.\n\t expected: %v\n\t got: %v", taghkid, testtag.Hkid)
	} else if !testtag.Verify() {
		t.Fatalf("GetTag Verify Fail")
	}

	prikey, err := services.GetKey(taghkid)
	if err != nil || !bytes.Equal(prikey.Hkid(), taghkid) || !prikey.Verify() {
		t.Logf("GetKey Fail")
		t.Fail()
	}
}
Example #4
0
func TestKeyGen(t *testing.T) {
	t.SkipNow()
	priv := objects.KeyGen()
	log.Printf("TestKeyGen\nX = %v\nY = %v\nD = %v\n", priv.PublicKey.X,
		priv.PublicKey.Y, priv.D)
	err := services.PostKey(priv)
	if err != nil {
		t.Errorf("Error %v", err)
	}
	services.PostBlob(elliptic.Marshal(priv.PublicKey.Curve,
		priv.PublicKey.X, priv.PublicKey.Y))
}
Example #5
0
func (o openFileHandle) Publish() error { //name=file name
	//log.Printf("buffer contains: %s", o.buffer)
	bfrblob := objects.Blob(o.buffer)
	log.Printf("Posting blob %s\n-----BEGIN BLOB-------\n%s\n-------END BLOB-------", bfrblob.Hash(), bfrblob)
	postblobErr := services.PostBlob(bfrblob)
	if postblobErr != nil {
		return postblobErr
	}

	//Protection against nil pointer(note that this should not be able to occur)
	if o.file != nil {
		o.file.Update(&o, bfrblob.Hash())
	}
	o.parent.Publish(bfrblob.Hash(), o.name, "blob")
	return postblobErr
}
Example #6
0
func TestPostBlob(t *testing.T) {
	services.PostBlob(objects.Blob{})
	testhkid := objects.HkidFromDString("65232373562705602286177837897283294165955126"+
		"49112249373497830592072241416893611216069423804730437860475300564272"+
		"976762085068519188612732562106886379081213385", 10)
	testpath := "TestPostBlob"
	indata := []byte("TestPostData")

	services.Post(testhkid, testpath, objects.Blob(indata))
	outdata, err := services.Get(testhkid, testpath)
	if !bytes.Equal(indata, outdata) || err != nil {
		t.Fail()
	}
	//log.Printf("\n\tkey: %s\n\tpath: %s\n\tindata: %s\n\toutdata: %s\n",
	//	testhkid.Hex(),
	//	testpath,
	//	indata,
	//	outdata)
}
Example #7
0
func BenchmarkLowLevelRemoveBlob(b *testing.B) {

	//Generate HKID from Private Key String
	commitHkid := objects.HkidFromDString("25237284271696152257500017172738061121437774519248"+
		"4973944393756241918592441392745192478415977843322020140748800825891925253"+
		"1173359792875255431921541368062567", 10)

	for i := 0; i < b.N; i++ {

		//Create Blob and add it to Commit List
		testBlob := objects.Blob([]byte("BlobToBeDeleted"))
		_ = services.PostBlob(testBlob)
		testList := objects.NewList(testBlob.Hash(), "blob", "blobToBeDeleted")
		services.PostList(testList)
		testCommit := objects.NewCommit(testList.Hash(), commitHkid)
		services.PostCommit(testCommit)

		//Check to make sure Blob was added to Commit List
		commitFromHkid, err := services.GetCommit(commitHkid)
		_, err = services.GetList(commitFromHkid.ListHash)
		listEntry, found := testList["blobToBeDeleted"]
		if !found {
			b.Fatalf("Error: Blob could not be found in list")
		}
		_, err = services.GetBlob(listEntry.Hash.(objects.HCID))
		if err != nil {
			b.Fatalf("Error: Blob could not be retrieved using HID from list")
		}

		//Remove Blob from Commit List
		testListDelete := testList.Remove("blobToBeDeleted")
		testCommitDelete := testCommit.Update(testListDelete.Hash())
		services.PostCommit(testCommitDelete)

		//Check to make sure blob Does Not Exist in Commit List
		dneCommit, _ := services.GetCommit(commitHkid)
		dneList, _ := services.GetList(dneCommit.ListHash)
		_, found = dneList["blobToBeDeleted"]
		if found {
			b.Fatalf("Error: Blob incorrectly found in list")
		}
	}
}