예제 #1
0
def TestDigestSum():
  test_data = []
  for s in test_vectors:
    dig = c4.Identify(s)
    id, err = c4.parse(test_vector_ids[0][i])
    if err != nil:
      eprint("unexpected error %q", err)

    if id.string() != dig.string():
      eprint("IDs don't match, got %q expected %q", id, dig)

    if id.string() != test_vector_ids[0][i]:
      eprint("IDs don't match, got %q expected %q", id.string(), test_vector_ids[0][i])

    test_data = append(test_data, testDataType{s, id, test_vector_ids[0][i]})
예제 #2
0
def test_all_ffff():
  b = []
  for i in range(64):
    b.append(chr(0xFF))
  data = ''.join(b)

  if c4.ID(data).string() != "c467rpwLCuS5DGA8KGZXKsVQ7dnPb9goRLoKfgGbLfQg9WoLUgNY77E2jT11fem3coV9nAkguBACzrU1iyZM4B8roQ":
    eprint("IDs don't match, got ", id.string(), " expcted ", "c467rpwLCuS5DGA8KGZXKsVQ7dnPb9goRLoKfgGbLfQg9WoLUgNY77E2jT11fem3coV9nAkguBACzrU1iyZM4B8roQ")
    return False

  id2, err = c4.parse("c467rpwLCuS5DGA8KGZXKsVQ7dnPb9goRLoKfgGbLfQg9WoLUgNY77E2jT11fem3coV9nAkguBACzrU1iyZM4B8roQ")
  if err:
    eprint("Unexpected error ", err)
    return False

  for bb in id2.value:
    if bb != chr(0xFF):
      eprint(bb, "incorrect Parse results")
      return False
  return True
예제 #3
0
def test_all_0000():
  b = []
  for i in range(64):
    b.append(chr(0))
  data = ''.join(b)

  if c4.ID(data).string() != "c41111111111111111111111111111111111111111111111111111111111111111111111111111111111111111":
    eprint("IDs don't match, got ", id.string(), " expcted ",
           "c41111111111111111111111111111111111111111111111111111111111111111111111111111111111111111")
    return False

  id2, err = c4.parse(
      "c41111111111111111111111111111111111111111111111111111111111111111111111111111111111111111")
  if err:
    eprint("Unexpected error ", err)
    return False

  for bb in id2.value:
    if bb != chr(0):
      eprint(bb, "incorrect Parse results")
      return False
  return True
예제 #4
0
def test_append_order():
  byteData = [
      [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 58],
      [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0d, 0x24],
      [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0xfa, 0x28],
      [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xac, 0xad, 0x10]
  ]

  expectedIDs = ["c41111111111111111111111111111111111111111111111111111111111111111111111111111111111111121", "c41111111111111111111111111111111111111111111111111111111111111111111111111111111111111211", "c41111111111111111111111111111111111111111111111111111111111111111111111111111111111112111", "c41111111111111111111111111111111111111111111111111111111111111111111111111111111111121111"]

  k = 0
  for num in byteData:
    b = []
    for c in num:
      b.append(chr(c))
    id = c4.ID(''.join(b))

    if id.string() != expectedIDs[k]:
      eprint("IDs don't match, got ", id.string(), " , expcted ",  expectedIDs[k])
      return False

    id2, err = c4.parse(expectedIDs[k])
    if err:
      eprint("Unexpected error ", err)
      return False

    i = 0
    for bb in id2.value:
      if bb != chr(byteData[k][i]):
        eprint(bb, "incorrect Parse results")
        return False
      i = i + 1
    k = k + 1
  return True
예제 #5
0
def test_parse():
  tests =  [
    { "in": "c43ucjRutKqZSCrW43QGU1uwRZTGoVD7A7kPHKQ1z4X1Ge8mhW4Q1gk48Ld8VFpprQBfUC8JNvHYVgq453hCFrgf9D",
      "err": None,
      "exp": "This is a pretend asset file, for testing asset id generation.\n"
    },
    {
      "in":  "c430cjRutKqZSCrW43QGU1uwRZTGoVD7A7kPHKQ1z4X1Ge8mhW4Q1gk48Ld8VFpprQBfUC8JNvHYVgq453hCFrgf9D",
      "err": "invalid character at 3",
      "exp": ""
    },
    {
      "in":  "c430cjRutKqZSCrW43QGU1uwRZTGoVD7A7kPHKQ1z4X1Ge8mhW4Q1gk48Ld8VFpprQBfUC8JNvHYVgq453hCFrgf9",
      "err": "is not 90 characters long",
      "exp": ""
    }
  ]

  i = 0
  for test in tests:
    id, err = c4.parse(test["in"])
    if test["err"] is not None:
      if not err:
        eprint("Expected error but got none")
        return False
      elif err != test["err"]:
        eprint("incorrect error got ", err, " expected ", test["err"])
        return False
      continue
    elif err is not None:
      eprint("Unexpected error ", err)
      return False

    expectedID = c4.Identify(test["exp"])
    if expectedID != id:
      eprint("IDs don't match, got ", _stringOf(id), ", expcted ",  _stringOf(expectedID))
      return False
  return True
예제 #6
0
from pyc4 import c4

incoder = c4.Encoder()
incoder.write(u'foo')
id = incoder.id()

print id.string()
id2 = c4.identify(u'bar')
print id2.string()

id3, err = c4.parse(id2.string())
if err:
    print "error: ", err
    exit

if id3:
    print id3.string()