def pem_finger(path=None, key=None, sum_type='sha256'):
 if (not key):
  if (not os.path.isfile(path)):
   return ''
  with fopen(path, 'rb') as fp_:
   key = ''.join([x for x in fp_.readlines() if x.strip()][1:(-1)])
 pre = getattr(hashlib, sum_type)(key).hexdigest()
 finger = ''
 for ind in range(len(pre)):
  if (ind % 2):
   finger += '{0}:'.format(pre[ind])
  else:
   finger += pre[ind]
 return finger.rstrip(':')

def pem_finger ( path = None , key = None , sum_type = 'sha256' ) : if ( not key ) : if ( not os . path . isfile ( path ) ) : return '' with fopen ( path , 'rb' ) as fp_ : key = '' . join ( [ x for x in fp_ . readlines ( ) if x . strip ( ) ] [ 1 : ( - 1 ) ] ) pre = getattr ( hashlib , sum_type ) ( key ) . hexdigest ( ) finger = '' for ind in range ( len ( pre ) ) : if ( ind % 2 ) : finger += '{0}:' . format ( pre [ ind ] ) else : finger += pre [ ind ] return finger . rstrip ( ':' )
pass in either a raw pem string .