Don't use 2|| for control flow, use nested recover instead. Fix bug where creating a crypto context would dereference the handle, causing a type error.
parent
3419708ead
commit
c37d967da2
|
@ -13,35 +13,26 @@ M: windows-crypto-context dispose* ( tuple -- )
|
||||||
|
|
||||||
CONSTANT: factor-crypto-container "FactorCryptoContainer"
|
CONSTANT: factor-crypto-container "FactorCryptoContainer"
|
||||||
|
|
||||||
:: (acquire-crypto-context) ( provider type flags -- ret handle )
|
:: (acquire-crypto-context) ( provider type flags -- handle )
|
||||||
{ HCRYPTPROV } [
|
{ HCRYPTPROV } [
|
||||||
factor-crypto-container
|
factor-crypto-container
|
||||||
provider
|
provider
|
||||||
type
|
type
|
||||||
flags
|
flags
|
||||||
CryptAcquireContextW
|
CryptAcquireContextW win32-error=0/f
|
||||||
] with-out-parameters ;
|
] with-out-parameters ;
|
||||||
|
|
||||||
: acquire-crypto-context ( provider type -- handle )
|
: acquire-crypto-context ( provider type -- handle )
|
||||||
CRYPT_MACHINE_KEYSET
|
CRYPT_MACHINE_KEYSET (acquire-crypto-context) ;
|
||||||
(acquire-crypto-context)
|
|
||||||
swap 0 = [
|
|
||||||
GetLastError NTE_BAD_KEYSET =
|
|
||||||
[ drop f ] [ win32-error-string throw ] if
|
|
||||||
] when ;
|
|
||||||
|
|
||||||
: create-crypto-context ( provider type -- handle )
|
: create-crypto-context ( provider type -- handle )
|
||||||
flags{ CRYPT_MACHINE_KEYSET CRYPT_NEWKEYSET }
|
flags{ CRYPT_MACHINE_KEYSET CRYPT_NEWKEYSET } (acquire-crypto-context) ;
|
||||||
(acquire-crypto-context) win32-error=0/f *void* ;
|
|
||||||
|
|
||||||
ERROR: acquire-crypto-context-failed provider type ;
|
ERROR: acquire-crypto-context-failed provider type error ;
|
||||||
|
|
||||||
: attempt-crypto-context ( provider type -- handle )
|
: attempt-crypto-context ( provider type -- handle )
|
||||||
{
|
|
||||||
[ acquire-crypto-context ]
|
[ acquire-crypto-context ]
|
||||||
[ create-crypto-context ]
|
[ drop [ create-crypto-context ] [ acquire-crypto-context-failed ] recover ] recover ;
|
||||||
[ acquire-crypto-context-failed ]
|
|
||||||
} 2|| ;
|
|
||||||
|
|
||||||
: initialize-crypto-context ( crypto-context -- crypto-context )
|
: initialize-crypto-context ( crypto-context -- crypto-context )
|
||||||
dup [ provider>> ] [ type>> ] bi attempt-crypto-context >>handle ;
|
dup [ provider>> ] [ type>> ] bi attempt-crypto-context >>handle ;
|
||||||
|
|
Loading…
Reference in New Issue